-
Notifications
You must be signed in to change notification settings - Fork 64
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
Configure types referenced via @ExtendWith
, @ArgumentsSource
, etc. for reflection
#54
Comments
I took another look at candidate annotations for this support and discovered I'd missed the following: So I'll update this issue's description accordingly. |
One approach we could take to help support these features is to introduce a new service ( default void onLoad(ConfigRegistry registry) {
}
default void onTestClassRegistered(Class<?> testClass, ConfigRegistry registry) {
} where |
I've been saying for about 6 months now that we will eventually need an extension/plugin mechanism for So, I am glad you came to the same conclusion! 😄 As for what the extension/plugin SPI is called, let's hold off on deciding on a concrete name until we have worked out the actual API. So why don't you make a concrete proposal (perhaps simply continuing with your |
For the time being, the Implementing this mechanism will also allow us to greatly simplify the This means, as a proof of concept, we should aim to extract the configuration in the |
It really seems like the best tool for this purpose :) As soon as I get a chance, I'll put together an initial implementation on which we can discuss more - I also agree that something like this should at first be used only internally by us and potentially open it up in the future as an API. |
Overview
As discussed in #50 (comment), the
JUnitPlatformFeature
currently has hard-coded reflection config for JUnit Jupiter'sCsvArgumentsProvider
, but as we see from #50 and #51 theJUnitPlatformFeature
would at the very least need to configure alljunit-jupiter-params
ArgumentProvider
implementations for reflective instantiation.That is possible, but it would not help with
ArgumentProvider
implementations from users or third party libraries that are loaded by JUnit Jupiter via@ArgumentSource
declarations (such as the@ArgumentsSource(MethodArgumentsProvider.class)
declaration on@MethodSource
).Details
The broader topic that needs to be addressed is how to automatically register test-related types for reflection.
Within JUnit Jupiter, the following annotations are used to refer to types or methods that JUnit accesses via reflection:
@ExtendWith
,@ArgumentsSource
,@TestMethodOrder
,@DisplayNameGeneration
,@IndicativeSentencesGeneration
,@ConvertWith
,@AggregateWith
,@EnabledIf
,@DisabledIf
,@MethodSource
.These fall into two categories.
Type References
@ExtendWith
,@ArgumentsSource
,@TestMethodOrder
,@DisplayNameGeneration
,@IndicativeSentencesGeneration
,@ConvertWith
, and@AggregateWith
are used to reference a type that will be instantiated via reflection.Method References
@MethodSource
,@EnabledIf
, and@DisabledIf
are used to reference methods that will be invoked via reflection.If the method that is referenced is local to the test class -- for example,
@MethodSource("localMethod")
-- there should not be any need for additional reflection configuration, since all methods of the test class should have already been registered for reflection. However, there may potentially be an issue if the referenced method is declared in a super type.On the contrary, if one of these three annotations is used to reference a
static
method in a different class (i.e., not within the test class itself) -- for example,@MethodSource("org.example.MyTestUtils#externalMethod")
-- the declared methods in the external class will need to be opened up for reflection.Deliverables
@ExtendWith
,@ArgumentsSource
,@TestMethodOrder
,@DisplayNameGeneration
,@IndicativeSentencesGeneration
,@ConvertWith
,@AggregateWith
,@EnabledIf
,@DisabledIf
,@MethodSource
for reflection.JUnitPlatformFeature
for types that will be picked up automatically by changes made in conjunction with this issue.The text was updated successfully, but these errors were encountered: