Skip to content

Constructor parameter resolution for outer class fails while using @Nested and test template context provider #5584

@A248

Description

@A248

@Nested, constructor parameter resolution, and test template context providers don't play well together.

This is best demonstrated by example:

@ExtendWith(ContextProvider.class)
public class FailingTest {

    private final Token token;

    public FailingTest(Token token) { // Supplied by test template context provider
        this.token = token;
    }

    @TestTemplate
    public void runOuter() {
       // Passes
    }

    @Nested
    @ExtendWith(ContextProvider.class)
    public class Inner {

        @TestTemplate
        public void runInner() {
          // FAILS!
        }
    }
}

Description

Test templates can provide additional extensions according to the TestTemplateInvocationContextProvider and the invocation context it supplies.

Those extensions can include parameter resolvers. Normally, this works fine.

However, when using @Nested, the constructor parameters on the outer class cannot be resolved by the extension.

Steps to reproduce

Reproducer here:
https://github.com/A248/junit-ctor-params-nested-context-provider-reproducer

Context

  • Used versions (Jupiter/Vintage/Platform): 5.14.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions