-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support declarative extension registration on fields and parameters #864
Comments
Like? class SudokuTests {
@RepeatedTest(10)
void testSomeGeneratedSudokus(@Random int seed) {
assertTrue(Sudoku.generate(seed).isSolvable());
}
} Edit: now with simple class body w/o any parameter resolver on the class level. |
Yes. But without registering any parameter resolver on the class level and without the chance of |
Related discussion on Twitter about being able to register extensions on parameters: |
Renamed issue to align with the title of #497 and features discussed in the aforementioned Twitter thread. |
Updated scope to include registration via fields and parameters. |
Current work on this issue can be viewed in the following branch: |
in progress |
…each other Prior to this commit, @ExtendWith fields and @RegisterExtension fields were sorted using @order, but extensions registered via @ExtendWith fields were always registered first (before extensions registered via @RegisterExtension fields). This commit ensures that @RegisterExtension fields and @ExtendWith fields are sorted via @order relative to each other. See #864, #2680
This commit introduces extensions registered explicitly via @RegisterExtension to verify the respective ordering with extensions registered implicitly via @ExtendWith on fields. Issue: #864
Prior to this commit, @ExtendWith could only be declared on types (i.e., classes, interfaces, annotations) and methods. @ExtendWith can now be declared directly on fields and parameters as well. See #864, #2680
…each other Prior to this commit, @ExtendWith fields and @RegisterExtension fields were sorted using @order, but extensions registered via @ExtendWith fields were always registered first (before extensions registered via @RegisterExtension fields). This commit ensures that @RegisterExtension fields and @ExtendWith fields are sorted via @order relative to each other. See #864, #2680
This commit introduces extensions registered explicitly via @RegisterExtension to verify the respective ordering with extensions registered implicitly via @ExtendWith on fields. Issue: junit-team#864
Issue: junit-team#864
Prior to this commit, an exception was thrown if a @RegisterExtension field was declared private. This commit removes this restriction. Closes junit-team#2688 See junit-team#864, junit-team#2680
Prior to this commit, @ExtendWith could only be declared on types (i.e., classes, interfaces, annotations) and methods. @ExtendWith can now be declared directly on fields and parameters as well. See junit-team#864, junit-team#2680
…each other Prior to this commit, @ExtendWith fields and @RegisterExtension fields were sorted using @order, but extensions registered via @ExtendWith fields were always registered first (before extensions registered via @RegisterExtension fields). This commit ensures that @RegisterExtension fields and @ExtendWith fields are sorted via @order relative to each other. See junit-team#864, junit-team#2680
Overview
Original title: "Support ParameterResolver registration via @ResolveWith on parameter"
While experimenting with parameter resolvers I realized that they can not be applied like argument converters can, i.e. by annotating the parameter directly. This complicates their application and implementation if they are "annotation based".
An example is the
@Mock
proof of concept. The resolver has to be applied to the test method or class and because of that has to check the individual parameter for the presence of the@Mock
annotation. This indirection causes unnecessary complexity for implementers and users of the extension.Original Proposal
I propose an annotation similar to
@ConvertWith
, e.g.@ResolveWith
, that takes precedence over all registered parameter resolvers. It does not need asupports
method because it is assumed to support the parameters it is applied to. If it turns out duringresolve
that that's not the case, the test should be aborted by an exception.With this mechanism,
@Mock
(and I am planning to write something like@Random
) would get simpler to use because they only need to be applied in one place.More broadly, I think parameter resolvers and argument converters are conceptually very similar and the API would hence improve considerably if both would operate similarly as well. In that regard I already opened #853, which proposes an extension point to register converters at the method and class level. Together with this issue, the two aim to align both mechanisms.
If there is interest in this, I would give it a shot, preferably together with #853.
Related Issues
The text was updated successfully, but these errors were encountered: