-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support registration of global extensions via ServiceLoader mechanism #448
Comments
There is a good reason: Tests should be easy to understand. However, I feel your pain. Maybe we could make this an opt-in feature that can be turned on via a configuration parameter / system property. @junit-team/junit-lambda What do you think? |
Hmm, I see you're point there. How would a opt-in feature look like? |
You could, e.g., enable global extensions via a system property. That would give you at least an indication... |
I still feel that we should not go in this direction:
While adding (very) more complexity to the extension registration, I cannot see the huge advantages that shall come along with this proposal. Even worse, it makes it more complex as we might also have to add a mechanism to "unregister" a globally registered extension for certain test cases. This is not worth the effort. |
I very often wished there was a feature like this. Most often the scenario was like this:
What I ended up doing is: manually splitting all test in two groups, run them, check if my new test fails. If yes, split the tests in two again ... until finally I identify one bad test. Rinse and repeat until all bad apples are found. With a global extention registry I could write a service that checks for left over state after each test and get a list of tests that need fixing. Therefore I vote for such a feature. |
The Spring TestContext Framework supports this for the For example, Spring Boot and Spring Security can auto-magically contribute custom testing features without requiring the user to do anything other than add the But that automatic registration itself is only part of the picture. The more important piece of the puzzle is that users can upgrade to a new version of Spring Security Test and benefit from its new testing features (provided via extensions/listeners) without having to configure every single test class in the entire test suite to register the new Spring Security Test feature alongside the existing configuration for the previous version of Spring Security Test. Thus, I am in favor of supporting this feature in general and at the very least as an opt-in only feature. |
@junit-team/junit-lambda, and objections on pulling this in before 5.0 GA? |
Tentatively slated for M5. |
@sbrannen where would be the correct place to add the according documentation to? |
In the Registering Extensions section of the User Guide. |
@sbrannen I've updated my pull request with some documentation |
Now slated for M4. |
Prior to this commit, custom extensions could only be registered declaratively via @ExtendWith. This commit introduces support for auto-detection of extensions via Java's ServiceLoader mechanism. Such extensions will be automatically registered after the default global extensions in JUnit Jupiter (e.g., support for TestInfo, TestReporter, etc.). Furthermore, this feature is disabled by default but can be enabled via a JVM system property or JUnit Platform configuration parameter. Consult the JavaDoc and User Guide for details. Issue: #448
Resolved in 473aa1a. |
In addition, default extensions are now logged at TRACE level. Issue: #448
Overview
Since we have over 2000 tests that we would have to annotate with
@ExtendWith
, it would be nice to just add also extensions using theMETA-INF/service/org.junit.jupiter.api.extension.Extension
mechanism (later under JDK 9 via service within module-info).Is there a good reason to not have this possibility?
Pull Requests
The text was updated successfully, but these errors were encountered: