-
-
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 programmatic extension registration via fields #497
Comments
@sbrannen do you have a coarse estimation when M3 might be available? |
@juergenzimmermann, perhaps by the end of October. The core team is swamped with work, so we are unfortunately forced to push back the release dates. |
We are migrating project from Juni4 to Junit5. Rule provides me with three callback methods So I can be aware what is the test result - failed, success or skipped - @mmerdes has made a good work of adapting existing junit4 rules to extensions of junit5 I've researched this topic and came to realise that for now there is no strait reliable way to implement this feature using only Junit5 extension model. The closest extension is AfterTestExecutionCallback but its callback method Now when you plan UseExtension my question is: Are you planning to provide users with test result callback or pass info of test result ? If not please take it into account. Sooner or later there will be users that encounter the same problem. Although I do not know implementation details I suppose that UseExtension as Suggestion: |
@SqAutoTestTeam, this issue focuses solely on programmatic extension registration via fields. Consequently, we are not considering any changes to extension APIs in conjunction with this issue. If you would like to propose additional Extension APIs, please create a new issue dedicated to your proposal. Thanks |
I'd like to add some wishes here:
|
This commit introduces a test that verifies that a @RegisterExtension field can be supplied by a dependency injection framework (e.g., the Spring Framework, Guice, etc.) whose extension performs field injection via the TestInstancePostProcessor API. Issue: #497
Feature branch merged into |
This commit introduces a test that verifies that a @RegisterExtension field can be supplied by a dependency injection framework (e.g., the Spring Framework, Guice, etc.) whose extension performs field injection via the TestInstancePostProcessor API. Issue: junit-team#497
Status Quo
It is currently possible to register extensions declaratively via
@ExtendWith
on a class or method but not on a field.Furthermore, it is currently impossible for a user of an extension to provide input to the extension programmatically. Rather, in order to make an extension configurable, current extension implementations typically provide a custom annotation, but such an annotation is hindered by the limitations of what can be declared as an annotation attribute in Java.
See the discussion in Spring REST Docs for further background information.
Related Issues
Proposal for Programmatic Extension Registration
In general, it should be possible for an extension to be registered programmatically -- for example, via a field or a factory method. This would allow a user to pass arguments to the extension's constructor (or
static
factory method) or to construct the extension programmatically, for example, via a method that returns the configured extension instance.With regard to migrations from JUnit 4 to JUnit Jupiter, it should be possible to migrate a JUnit 4 rule from this:
... to the following in JUnit Jupiter:
Considerations
@ExtendWith
annotation could technically be repurposed for such use cases, the JUnit Team feels it would be better to introduce a new annotation dedicated to this purpose. The current proposed name is@RegisterExtension
, but this may change.Deliverables
@RegisterExtension
where the field's value is used as the extension instance.The text was updated successfully, but these errors were encountered: