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
Investigate parameter targeting of CartesianProductTest arguments source annotations #415
Comments
My two cents: I personally consider mimicking JUnit's It could still be fine if the example above is an alternative way of declaring the parameters, but then I am wondering if it's worth offering multiple ways to do the same thing (and maybe supporting combinations of both ways?) |
The main reason I opened this issue is because this is a frequently asked question. I would like to have a discussion/discovery about this, so I can link to it as an explanation, i.e.: "This is not possible, we investigated this in #415" or "While this is possible, the team came to a decision to not support it - see discussion on #415" or we might just decide to support it but discourage users from using it, etc. ETA: "frequently" as in 2 people have asked this so far. |
With the discovery of the repeatable annotations bug (#447), this investigation should have a bit more priority (it could solve the bug - if it works). |
The similarity to Let's discuss first whether we think this is a good idea - maybe you can support that conversation by digging into the implementation or even working on a proof of concept. Once we know whether we prefer this solution and by how much and how complex it is to implement, we can discuss whether we offer one (which one?) or both approaches and how to possibly migrate if that becomes necessary. |
While developing the proof of concept for #49 yesterday, I created annotations @ParameterizedTest
@RandomArguments(count = 4)
void test(
@RandomString(minLength = 5, maxLength = 7) String beer,
@RandomInt(min = 8, max = 24) int proof) {
// ...
} That worked really well. I think there's potential to revamp the Cartesian product extension and make it much more powerful by more easily interacting with a wide variety of different annotations: @CartesianProductTest
void test(
@StringValues( "A", "B", "C" ) String str,
@EnumValues(ChronoUnit.class) ChronoUnit unit,
@LongRange(from = 1, to = 10) long l,
@FromMethod("userSupplier") User u,
@RandomIntegers(count = 4) int i) {
// ...
} |
While reviewing a part of #487, I wrote this comment:
Thoughts? |
I want to point out that we didn't have subpackages so far, so starting to do that would be quite the change and open the "which extensions need their own packages" can of worms that we prevented so far. |
While working on #487, we stumbled on a very interesting question: Now that we consider adding a new package for Cartesian product tests, can we shorten the names of the annotations that work with it? While discussing this, we discovered five ways to organize and name things. Side note: In any of the following summaries, I'll assume we'll rename Side note II: Range sources have to keep their names because they need to fit in with the parameterized test annotations. Long NamesBasically as they are, in the existing or a new package:
Short NamesIn a dedicated package, we could shorten the names:
Very Short NamesIn a dedicated package, we could shorten the names even more:
NestedNested in
When importing inner classes (which IntelliJ doesn't do by default [by default?]), Duplicated and NestedDuplicated and then the duplication nested within the original (cue Inception joke);
Users can choose between the outer or inner annotations. Thoughts?Thoughts? |
My thoughts:
|
I like the Long and the Nested names, cause they are clearly associated with the CartesainProduct-Extection |
The former @CartesianProductTest extension closely mirrored Jupiter's @ParameterizedTest annotation. Since then users came up with the idea that instead of providing arguments in annotations on the method, they could be provided on the parameters themselves. // BEFORE @CartesianProductTest @CartesianValueSource(ints = { 1, 2 }) @CartesianValueSource(ints = { 3, 4 }) void myCartesianTestMethod(int x, int y) { // passing test code } // NOW @CartesianTest void myCartesianTestMethod( @values(ints = { 1, 2 }) int x, @values(ints = { 3, 4 }) int y) { // passing test code } The old variant is still around, but deprecated and will be removed in the next major release. The new variant is different in more ways than just where annotations are placed: * new package `org.junitpioneer.jupiter.cartesian` * shorter name `@CartesianTest` * to keep parameter annotations short while avoiding collisions, they are now inner types of `@CartesianTest` (so in the example above, the full name is `@CartesianTest.Values` Closes: #415 PR: #487
Cartesian tests version 1 required users to annotate the test method to define individual arguments. While version 2 of this extension moves the bulk of configuration to parameter-level annotations it should still allow method-level annotations to define the full set of sets, for example to define them in a CSV or JSON file. This is now possible. It's achieved by turning `CartesianArgumentsProvider` into an internal marker interface with two public extensions: * `CartesianParameterArgumentsProvider` (for providing arguments for an individual parameter, i.e. takes on the former meaning of `CartesianArgumentsProvider`) * `CartesianMethodArgumentsProvider` (for providing arguments for all parameters) Related to #415 PR: #540
* unlist old documentation from /docs * fix cross-links * mention the correct version (1.6.0) * guess later 2.0 release date (2022) Related to: #415
JUnit (more precisely the module `org.junit.platform.commons`) needs to reflectively access Pioneer packages. Since some classes aren't public, this fails with an `InaccessibleObjectException` if Pioneer is placed on the module path. To fix this, the packages must be opened. Furthermore, this change fixes a mistake from #415 and exports the new package `org.junitpioneer.jupiter.cartesian`. Closes: #539 PR: #597
A very strong argument can be made that it's much more convenient to define a CartesianProductTest like the following:
Investigate if this is possible - it is likely it is not possible, because of how the annotations invoke their corresponding
ArgumentsProvider
implementations, but it might work.The text was updated successfully, but these errors were encountered: