Skip to content

Introduce ExtensionContext.getEnclosingTestClasses() for use with AnnotationSupport #4375

@marcphilipp

Description

@marcphilipp

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions