ApprovalTests.Java icon indicating copy to clipboard operation
ApprovalTests.Java copied to clipboard

Ability to store approval files under different folder

Open mzagar opened this issue 12 years ago • 10 comments

I'd like the ability to store generated approval files under different folder and not strictly in the folder where my test source code is located.

For example, when using maven-type projects, my source files are located under PROJECT/src/test/java/some/package and I'd like approval files to be generated under PROJECT/src/test/resources/some/package. This helps keeping the test source folder clean and free of lots of approval files, especially when there are lots of test classes with lots of tests using Approvals.

I will submit a pull request with my proposed solution to this issue.

mzagar avatar Apr 22 '13 20:04 mzagar

My more modern approval java port at (https://github.com/nikolavp/approval) can archieve this with something I call PathMappers. Actually this is the main usecase for them, you can find more information in the docs

nikolavp avatar Sep 01 '14 19:09 nikolavp

Was this PR ever made? Or included in this non-fork?

talios avatar Aug 19 '19 01:08 talios

I believe @LarsEckart's PR #100 for further options is a step in this direction. The to-do list now also contains "Options for file path":

https://github.com/LarsEckart/ApprovalTests.Java/blob/6eaae958b2ec66d7d4a79295e4ec93655ca0f2eb/todo.txt#L3

Ideally, this can be configured globally viaa properties file or something similar. Otherwise, one would have to set this for each verify I guess?

beatngu13 avatar Jul 21 '20 11:07 beatngu13

Triggered by another PR, we updated documentation as this feature is already available: https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/Configuration.md#package-level-settings

Does this help?

LarsEckart avatar Jan 07 '21 10:01 LarsEckart

Thanks for the hint @LarsEckart, works for me!

Side note: Since PackageSettings field names are upper camel case, some IDEs might create warnings for not following Java naming conventions. Also the class name may confuse others when looking at the code base / tests because it is not linked to ApprovalTests.

For a future release, instead of:

public class PackageSettings {
    public static String ApprovalBaseDirectory = "../resources/";
}

Maybe you want to consider something like:

class ApprovalTestsConfiguration {
    static final String APPROVAL_BASE_DIRECTORY = "../resources/";
}

✌️

beatngu13 avatar Jan 16 '21 23:01 beatngu13

Could we take this one step further with package level annotations?

@ApprovalBaseDirectory("../resources/')
package com.foo;

which gets stored in package-info.java - see https://puredanger.github.io/tech.puredanger.com/2007/02/28/package-annotations for some details.

talios avatar Apr 21 '21 20:04 talios

We didn't know about package level annotations, it looks interesting! Tonight we didn't get to it but maybe next week :-)

LarsEckart avatar Apr 26 '21 21:04 LarsEckart

@LarsEckart did @ApprovalBaseDirectory make it into approval tests?

talios avatar Feb 25 '22 03:02 talios

@talios sorry, we didn't get to it and then it disappeared from my radar. lately we were spending time on our pipelines but I hope to soon tackle our open issues here again more actively.

LarsEckart avatar Feb 25 '22 05:02 LarsEckart

@LarsEckart All good - I'd totally forgotten about it til I ran into some code locally references this ticket ;)

talios avatar Feb 25 '22 06:02 talios