Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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