Skip to content
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 ExtensionContext.getEnclosingTestClasses() for use with AnnotationSupport #4375

Closed
1 task done
marcphilipp opened this issue Mar 7, 2025 · 0 comments · Fixed by #4376
Closed
1 task done

Comments

@marcphilipp
Copy link
Member

marcphilipp commented Mar 7, 2025

In #4131, the AnnotationSupport.findAnnotation(Class, Class, SearchOption) method was deprecated in favor of the new AnnotationSupport.findAnnotation(Class, Class, List) method. When called with SearchOption.INCLUDE_ENCLOSING_CLASSES it looks up annotations on the passed class or its static enclosed types. In the context of @Nested tests that was not correct, as annotations (such as @DisplayNameGeneration) need to be looked up on the runtime enclosing types which differ in case a @Nested class is declared in a superclass of the test class.

In order to call the new method, ExtensionContext should provide a getEnclosingTestClasses(): List<Class<?>> method that can be passed like this:

AnnotationSupport.findAnnotation(
    extensionContext.getRequiredTestClass(),
    MyAnnotation.class,
    extensionContext.getEnclosingTestClasses()
);

Deliverables

  • Introduce ExtensionContext.getEnclosingTestClasses() method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants