Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvocationInterceptor is not invoked for a parameterized test #3808

Closed
ArvindJoshi-okta opened this issue May 8, 2024 · 2 comments
Closed

Comments

@ArvindJoshi-okta
Copy link

ArvindJoshi-okta commented May 8, 2024

JUnit 5 - 5.10.2

Steps to reproduce

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)
class MyTest {

    @ParameterizedTest
    @NullAndEmptySource
    void testNotSkipping(String test) {
    }

    @Test
    void testGettingSkipped() {
    }
}

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

class MyExtension implements InvocationInterceptor {

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

Looks like the annotation already extends an extension, maybe due to that, its not able to extend additional ones?

@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@API(
    status = Status.STABLE,
    since = "5.7"
)
@TestTemplate
@ExtendWith({ParameterizedTestExtension.class})
public @interface ParameterizedTest {

Context

  • Used versions (Jupiter/Vintage/Platform):
        <dependency>
               <groupId>org.junit.jupiter</groupId>
               <artifactId>junit-jupiter</artifactId>
               <version>5.10.2</version>
           </dependency>
  • Build Tool/IDE: Maven/IntelliJ
@BlueIce
Copy link

BlueIce commented May 9, 2024

According to the JavaDoc the interceptTestMethod method will only be called for Test-Methods:

Intercept the invocation of a @Test method.

For parameterized tests you need to use interceptTestTemplateMethod.

@ArvindJoshi-okta
Copy link
Author

ArvindJoshi-okta commented May 9, 2024

Thanks, @BlueIce, that worked!

@sbrannen sbrannen changed the title JUnit5 test isn't executing extension for a parameterized test InvocationInterceptor is not invoked for a parameterized test May 11, 2024
@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants