Class AsyncTestInvocationInterceptor

java.lang.Object
se.deversity.asynctest.extension.AsyncTestInvocationInterceptor
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.TestInstantiationAwareExtension

@API(status=STABLE) public class AsyncTestInvocationInterceptor extends Object implements org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.AfterEachCallback
Intercepts the execution of the test method and delegates it to the ConcurrencyRunner.

This interceptor skips the default JUnit invocation and instead runs the test body concurrently across multiple threads to maximize the chance of detecting race conditions.

Since:
1.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a AsyncTestInvocationInterceptor.
    AsyncTestInvocationInterceptor(AsyncTest asyncTest, int threadCount)
    Construct with an explicit thread count, used by the schedule-matrix path in @AsyncTest(threadCounts=...) where each matrix entry runs with its own count.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
    Reports the executors the run declared that the test's own @AfterEach methods did not shut down either.
    void
    interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestMethod

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • AsyncTestInvocationInterceptor

      public AsyncTestInvocationInterceptor(AsyncTest asyncTest)
      Creates a AsyncTestInvocationInterceptor.
      Parameters:
      asyncTest - the annotation on the test method, supplying the run configuration
    • AsyncTestInvocationInterceptor

      public AsyncTestInvocationInterceptor(AsyncTest asyncTest, int threadCount)
      Construct with an explicit thread count, used by the schedule-matrix path in @AsyncTest(threadCounts=...) where each matrix entry runs with its own count.
      Parameters:
      asyncTest - the annotation on the test method, supplying the run configuration
      threadCount - thread count to use instead of the annotation value, for a parameterised template
      Since:
      1.6.0
  • Method Details

    • interceptTestTemplateMethod

      public void interceptTestTemplateMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Throwable
      Specified by:
      interceptTestTemplateMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
      Throws:
      Throwable
    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Reports the executors the run declared that the test's own @AfterEach methods did not shut down either. JUnit calls an extension's afterEach after those methods, and the run's analysis came before them, so a pool closed in teardown is judged here (#996).
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
      Parameters:
      context - the invocation's extension context
      Since:
      1.13.2