-
-
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
Introduce zero invocations in test templates and parameterized tests #3890
base: main
Are you sure you want to change the base?
Conversation
Add a flag to ParameterizedTest to control arguments requirement. This allows users to explicitly opt out from validation of arguments set count and silently skip a test if no arguments are provided In general, support TestTemplateInvocationContextProvider returning zero invocation contexts. Such providers must override new interface method to indicate that the framework should expect "no context returned" Resolves junit-team#1477
Need this feature a lot! Is there a forecast for when it will be ready? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very promising! 👍
* @since 5.11 | ||
*/ | ||
@API(status = EXPERIMENTAL, since = "5.11") | ||
default boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default boolean mayReturnEmptyInvocationContext(ExtensionContext extensionContext) { | |
default boolean mayReturnZeroInvocationContexts(ExtensionContext context) { |
() -> "None of the supporting " + TestTemplateInvocationContextProvider.class.getSimpleName() + "s " | ||
+ providers.stream().map(provider -> provider.getClass().getSimpleName()).collect( | ||
joining(", ", "[", "]")) | ||
+ providers.stream().filter(p -> !p.mayReturnEmptyInvocationContext(extensionContext)).map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should filter them out here.
* to be invoked; never {@code null} | ||
* @return {@code true} to allow zero contexts, {@code false} (default) to fail execution in case of zero contexts. | ||
* | ||
* @since 5.11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 5.12 now
return findAnnotation(templateMethod, ParameterizedTest.class).map( | ||
parameterizedTest -> !parameterizedTest.requireArguments()).orElse( | ||
TestTemplateInvocationContextProvider.super.mayReturnEmptyInvocationContext(extensionContext)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return findAnnotation(templateMethod, ParameterizedTest.class).map( | |
parameterizedTest -> !parameterizedTest.requireArguments()).orElse( | |
TestTemplateInvocationContextProvider.super.mayReturnEmptyInvocationContext(extensionContext)); | |
return findAnnotation(templateMethod, ParameterizedTest.class) // | |
.map(parameterizedTest -> !parameterizedTest.requireArguments()) // | |
.orElse(false); |
* Signals that in the given {@linkplain ExtensionContext extension context} the provider may return zero | ||
* {@linkplain TestTemplateInvocationContext invocation contexts} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Signals that in the given {@linkplain ExtensionContext extension context} the provider may return zero | |
* {@linkplain TestTemplateInvocationContext invocation contexts} | |
* Signals that in the supplied {@linkplain ExtensionContext context} the provider may return zero | |
* {@linkplain TestTemplateInvocationContext invocation contexts}. |
Add a flag to ParameterizedTest to control arguments requirement. This allows users to explicitly opt out from validation of arguments set count and silently skip a test if no arguments are provided
In general, support TestTemplateInvocationContextProvider returning zero invocation contexts. Such providers must override new interface method to indicate that the framework should expect "no context returned"
Resolves #1477
Overview
Implemented the team decision described in this comment
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations