Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Junit5 extension] Run test multiple times for the same flag with different values #957

Open
aepfli opened this issue Sep 19, 2024 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aepfli
Copy link
Member

aepfli commented Sep 19, 2024

Sometimes, you want to ensure that your code behaves the same way for all code paths, even if different feature flags are involved.

Junit5 has parameterized tests to run multiple tests based on a source. This approach is not feasible for us, as it only generates an array of possible argument sets.

We need to find a way (maybe with our annotation) to create such tests. The cartesian test extension of JUnit Pioneer can be an inspiration for this https://github.com/junit-pioneer/junit-pioneer/blob/main/src/main/java/org/junitpioneer/jupiter/cartesian/CartesianTest.java

@aepfli aepfli added enhancement New feature or request help wanted Extra attention is needed labels Sep 19, 2024
@aepfli
Copy link
Member Author

aepfli commented Sep 19, 2024

theory crafting:

@FlagTest( name = "<flagName>", values = {"true", "false"}) 

@toddbaert
Copy link
Member

@UtkarshSharma2612 you might like this.

@UtkarshSharma2612
Copy link
Contributor

Sure let me check this

@UtkarshSharma2612
Copy link
Contributor

Hey @aepfli I understood the requirement a bit, I wanted to know do we want to change the existing testcases or write new testcases for all the providers with this custom annotation.

@aepfli
Copy link
Member Author

aepfli commented Sep 25, 2024

It is about adding another Test Annotation, so people who want to write unit tests to test all kinds of variations with one feature flag can use it. maybe some people want to verify, that the code works the same in both cases and is not effected.

eg. currently people would need to write two tests for a boolean to check if the code behaves as expected:

@Test
@Flag(name = "BOOLEAN_FLAG", value = "true")
void trueCase() {
    // your test code
}

@Test
@Flag(name = "BOOLEAN_FLAG", value = "false")
void falseCase() {
    // your test code
}

instead of this they code do

@FlagTest(name = "BOOLEAN_FLAG", values = { "true", "false" })
void bothCases() {
    // this block will run twice, once for 'true' and once for 'false'
}

does this make somewhat sense? - this is only about testing openFeature functionality with junit

@UtkarshSharma2612
Copy link
Contributor

Okay so we want to create a annotation or something that takes two parameters name (string) and values (List) and runs test cases for all the values. Correct me if I am wrong.

@aepfli
Copy link
Member Author

aepfli commented Sep 25, 2024

if you do need more guidance or pointers let me know, some people like the challenge of figuring things out on their own, some want more pointers, and i don't want to spoil the fun for you, if you like to dig on your own ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants