Class TimeoutExtension

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor

    class TimeoutExtension
    extends java.lang.Object
    implements org.junit.jupiter.api.extension.InvocationInterceptor
    This extension implements the timeout behavior of @Test, where a test is failed if it takes longer to finish than the specified time.

    Note that this is different from JUnit 4's @Test parameter, which would abandon the test if it ran to long and continue with the remainder of the suite. As Jupiter's extension API is currently not powerful enough to interact with its threading model, this could not be implemented.

    • Nested Class Summary

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

        org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.lang.String TEST_RAN_TOO_LONG  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.Optional<java.lang.Long> annotatedTimeout​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void interceptTestMethod​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      private void proceedWithTimeout​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ExtensionContext extensionContext, long timeout)  
      • 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, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestTemplateMethod
    • Constructor Detail

      • TimeoutExtension

        TimeoutExtension()
    • Method Detail

      • interceptTestMethod

        public void interceptTestMethod​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                        org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                        org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                                 throws java.lang.Throwable
        Specified by:
        interceptTestMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
        Throws:
        java.lang.Throwable
      • proceedWithTimeout

        private void proceedWithTimeout​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                        org.junit.jupiter.api.extension.ExtensionContext extensionContext,
                                        long timeout)
      • annotatedTimeout

        private java.util.Optional<java.lang.Long> annotatedTimeout​(org.junit.jupiter.api.extension.ExtensionContext context)