Interface TestInstantiationAwareExtension

All Superinterfaces:
Extension
All Known Subinterfaces:
InvocationInterceptor, ParameterResolver, TestInstanceFactory, TestInstancePostProcessor, TestInstancePreConstructCallback
All Known Implementing Classes:
TypeBasedParameterResolver

@API(status=MAINTAINED, since="5.13.3") public interface TestInstantiationAwareExtension extends Extension
TestInstantiationAwareExtension defines the API for Extensions that are aware of or influence the instantiation of test classes.

This interface is not intended to be implemented directly. Instead, extensions should implement one of the sub-interfaces listed below.

See getTestInstantiationExtensionContextScope(ExtensionContext) for further details.

Since:
5.12
  • Method Details

    • getTestInstantiationExtensionContextScope

      @API(status=MAINTAINED, since="5.13.3") default TestInstantiationAwareExtension.ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext)
      Determine whether this extension should receive a test-method scoped ExtensionContext during the instantiation of test classes or processing of test instances.

      If an extension returns TEST_METHOD from this method, methods defined in the following extension APIs will be called with a test-method scoped ExtensionContext instead of a test-class scoped context. Note, however, that a test-class scoped context will always be supplied if the PER_CLASS test instance lifecycle is used.

      When a test-method scoped ExtensionContext is supplied, implementations of the above extension APIs will observe the following differences.

      Note: The behavior which is enabled by returning TEST_METHOD from this method will become the default in future versions of JUnit. To ensure forward compatibility, extension authors are therefore advised to opt into this feature, even if they do not require the new functionality.

      Parameters:
      rootContext - the root extension context to allow inspection of configuration parameters; never null
      Since:
      5.12
      Implementation Note:
      There are no guarantees about how often this method will be called. Therefore, implementations should be idempotent and avoid side effects. If computation of the return value is costly, implementations may wish to cache the result in the Store of the supplied ExtensionContext.