google / TestParameterInjector

A simple yet powerful parameterized test runner for Java.
Apache License 2.0
397 stars 34 forks source link

JUnit5 test isn't executing extension for a parameterized test #46

Closed ArvindJoshi-okta closed 6 months ago

ArvindJoshi-okta commented 6 months ago

Hello, I am trying to add a JUnit5 extension to my test class, but for some reason, the parameterized test isn't executing it. A non-parameterized test within the same class seems to be executing the extension fine. Am I missing something?

Here's my test class

@ExtendWith(MyExtension.class)
public class MyTest {

    @TestParameterInjectorTest
    void testNotSkipped(@TestParameter boolean test) {
    }

    @Test
    void testSkipped() {
    }
}

Here's my extension, simplified to just skip the test

public class MyExtension implements InvocationInterceptor {

    @Override
    public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
                                    ExtensionContext extensionContext) {
        System.out.println("Skipping test ... ");
        invocation.skip();
    }
}
nymanjens commented 6 months ago

This sounds like more of a question about JUnit5, of which I'm unfortunately not an expert.

@TestParameterInjectorTest is annotated with the TestParameterInjectorExtension:

@TestTemplate
@ExtendWith(TestParameterInjectorExtension.class)
@Retention(RUNTIME)
@Target({METHOD})
public @interface TestParameterInjectorTest {}

Maybe JUnit5 isn't running your interceptor because of it already being claimed by a different extension, or maybe it is because of the way TestParameterInjectorExtension is implemented.

ArvindJoshi-okta commented 6 months ago

Thanks, following up here https://github.com/junit-team/junit5/issues/3808