junit-json-params
junit-json-params copied to clipboard
Ability to add variable in @JSONFileSource
Hi Joshka,
I am trying to something like this
@ParameterizedTest
@JsonFileSource(resources = "/testdata/"+testEnv+"/login.json").
Is it possible to do this? As of now, it is asking me to provide a constant. testEnv is a constant in this context. Help will be appreciated.
Best, CK
Hey - it's not something that I've tried specifically, but I suspect that you're running into the language constraints here. See https://stackoverflow.com/questions/28031784/in-java-why-this-error-attribute-value-must-be-constant and https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.1 for details.
I'm not sure that making this generally accept filename patterns would be a logical addition to the class (convince me otherwise though). Perhaps there's a way that you could write a MultipleJsonFileSource or something similar for this - something that allows this to produce multiple parameterized test runs for e.g. "testdata/*/login.json" seems like a neat idea.
Alternatively perhaps consider putting the environment name as a value in the login.json file containing an array of logins, and then use JUnit assumptions to ignore the environments that don't match the current test environment?
Hi Joshka,
Thanks for your reply! My situation is, my test data is different for Test and Prod! I want the same test cases to run with different data both in test and prod! I have these data in 2 different files. If prod data runs in Test, it will fail and vice versa.
Closing. See https://github.com/joshka/junit-json-params/issues/177 for more info.