-
-
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
Repeated @ExtendWith
meta-annotations on fields no longer supported in 5.11.x
#4054
Comments
Due to a minor bug in JUnit 5.11.x (junit-team/junit5#4054), fields meta-annotated with multiple `@ExtendWith` annotations are no longer recognized. We combine those annotations into single `@ExtendWith` annotations, which also looks better. Closes #2843.
Good catch, @ppkarwasz! 👍
Indeed, the switch to the use of We'll work on a fix. Cheers, Sam |
This was introduced in #3895 |
I've reproduced this in the following standalone test class, based on the examples from @ppkarwasz. package org.junit.jupiter.engine.descriptor;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.engine.extension.ExtensionRegistrar;
class ExtensionsUtilsTests {
@Test
void discoverExtensionsOnStaticFields() {
ExtensionRegistrar registrar = mock();
ExtensionUtils.registerExtensionsFromStaticFields(registrar, TestClassWithFields.class);
verify(registrar).registerExtension(Extension1.class);
verify(registrar).registerExtension(Extension2.class);
}
@Test
void discoverExtensionsOnInstanceFields() {
ExtensionRegistrar registrar = mock();
ExtensionUtils.registerExtensionsFromInstanceFields(registrar, TestClassWithFields.class);
verify(registrar).registerExtension(Extension1.class);
verify(registrar).registerExtension(Extension2.class);
}
static class Extension1 implements Extension {
}
static class Extension2 implements Extension {
}
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(Extension1.class)
@ExtendWith(Extension2.class)
@interface UseCustomExtensions {
}
static class TestClassWithFields {
@UseCustomExtensions
static int staticFieldMetaAnnotatedTwice;
@UseCustomExtensions
int instanceFieldMetaAnnotatedTwice;
}
} |
@ExtendWith
annotations on fields no longer supported in 5.11.x
@ExtendWith
annotations on fields no longer supported in 5.11.x@ExtendWith
meta-annotations on fields no longer supported in 5.11.x
JUnit Jupiter 5.11 introduced a regression regarding extension registration via fields. Specifically, repeated @ExtendWith annotations on composed annotations were no longer found. This commit fixes that regression by reintroducing support for finding @ExtendWith on custom composed annotations when @ExtendWith is used as a repeatable annotation. Fixes #4054 (cherry picked from commit d274794)
This has been fixed on |
Wow, this was fast! Thank You! |
Due to a minor bug in JUnit 5.11.x (junit-team/junit5#4054), fields meta-annotated with multiple `@ExtendWith` annotations are no longer recognized. We combine those annotations into single `@ExtendWith` annotations, which also looks better. Closes #2843. Note: the bug is already fixed and the fix will appear in version `5.11.3`.
Since version 5.11.x, if a field is meta-annotated with multiple
@ExtendWith
annotations, JUnit fails to detect them.The problem seems to be in
ExtensionUtils#streamExtensionFilteringFields
, which does not take into account repeatable annotations:junit5/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ExtensionUtils.java
Lines 204 to 209 in 8e9094d
Steps to reproduce
Meta-annotate some test class fields with multiple
@ExtendWith
annotations:Run the following test cases:
Context
The text was updated successfully, but these errors were encountered: