-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Introduce mechanism for programmatic extension management #506
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
Comments
Gist from https://stackoverflow.com/questions/47633819/injecting-test-classes-created-by-platform-launcher ... allow extension instances be part of a
|
@sormuras, the proposed So, unless I'm missing something, the proposal is not relevant to this GitHub issue. Furthermore, I am not a fan of registering extensions as mere objects at the level of the launcher API: I think extension registration should be left to the individual test engine implementations as it is now. In any case, that is a topic best suited for a different GitHub issue. |
I'd just like to add that we have existing JUnit 4 tests which used I can see that if I change the name of my extensions their callbacks will run in the desired order, but this is clearly not sustainable as this behaviour is likely to be JVM-dependent. My guess is that somewhere behind the scenes, these extensions are being fetched with |
In the meantime I've written a custom extension which runs the callbacks in the order the extensions were passed in to the constructor: https://gist.github.com/tomblench/999634f126e215132dcad2b0eccec870 |
Looks like a plain and simple solution. Do you register an instance of |
@sormuras that's correct |
I am not sure that I completely understood the proposal. From what I can see this would mean that users will have to register the ordering explicitly. However, as a library writer I would like to have control on the way my extensions are ordered, maybe even control how they are ordered in relation to other libraries ( ProposalWhy not allow For example we have a base extension that provides the basic support for what we need. Additionally we want to offer support for Spring, i.e. get the required beans from the |
@filiphr, thanks for the feedback. The That seems to work OK for the Spring ecosystem, since most of the key events are defined/supported by We discussed such an approach for JUnit Jupiter but in the end decided against it... since most extensions used with JUnit Jupiter will in fact not come from the JUnit Team. In other words, it would be difficult for various, competing third-party extensions to decide on a common number scheme to use for values returned from Of course, we are open to ideas and brainstorming on how to solve such a problem in the greater JUnit ecosystem. |
There's likely no need to "order" your extension relative to the If you need beans from the Spring |
@tomblench, that's a pretty nice workaround for the time being. However, such an approach has a few drawbacks.
|
That's a good point on the "wrapping", I guess I didn't notice because for my limited use case it didn't matter. |
Yeah, we take great care to ensure proper wrapping. Note the use of Lines 397 to 404 in e2a95a0
|
Yes the
I don't see why it would be difficult. Me as an extension writer will write an extension that has the default order, i.e. I don't care that much about it. Then I can have another extension that actually requires a different 3rd party extension that should run before my first one and after the 3rd party. Knowing this I can define a |
We're not concerned about cyclic dependencies. Rather, we are concerned about extension authors knowing what a valid/reasonable "order value" would be for a particular type of extension. The problem for the community is that such order values would typically be static in nature (e.g., hard coded as you suggested by But even in the case of the latter, how "informed" can an extension be? It obviously cannot know about every extension that has ever been developed or will be developed. |
In the end, even if JUnit Jupiter provides a mechanism for extensions to decide on their own "order value", there will be scenarios that require user intervention in order to override the extension-supplied order value due to incompatibilities with competing third-party extensions that know nothing of each other. |
Update: I've added a Deliverable for consideration of support for |
Being able to have JUnit show the "effective extensions" (which are applied, and what order) would be a good preliminary step in helping to work around some of these concerns. |
Another quick thought that would work (at least for my use cases, not sure about generally)... How about the ability for an extension to register that it depends on another extension? E.g.
I know in this trivial example I can just re-order the |
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution. |
This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue. |
|
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution. |
This issue still seems useful to have around. |
Background
This issue addresses some of the topics discussed in #112.
Status Quo
It is currently possible to register extensions declaratively via
@ExtendWith
on types and methods, and #497 will support programmatic extension registration via fields. However...Rationale
In order to avoid the introduction of an overly complex declarative model for sorting, appending, prepending, inserting, and removing extensions, we have opted for a programmatic means to achieve all of the above. Providing a programmatic means to achieve these goals frees developers to manage registered extensions as they see fit without any unnecessary restrictions imposed on them by the framework itself.
Considerations
Such a mechanism could itself be an
Extension
registered declaratively via@ExtendWith
; however, the current thinking in the team is that there should be one and only one such component registered at any given time. Since this is such a special case which affects all extensions which have been registered declaratively, it is therefore considered best to introduce a new declarative mechanism for registering this single component. Similarly, the API for such a component should therefore not extendExtension
since doing so would allow users to incorrectly register it via@ExtendWith
(in which case it would simply be silently ignored).Proposal
ExtensionManager
API that receives a list of all registered extensions as input and returns a list of extensions.@ManageExtensionsWith
annotation that allows the user to declare a single class reference for an implementation ofExtensionManager
.Related Issues
Deliverables
The text was updated successfully, but these errors were encountered: