@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
@Nested, constructor parameter resolution, and test template context providers don't play well together.This is best demonstrated by example:
Description
Test templates can provide additional extensions according to the
TestTemplateInvocationContextProviderand 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