Context
TestInstantiationAwareExtension and ExtensionContextScope were introduced in 5.12 to enable use cases such as field injection in nested test classes. For backward compatibility, by default, extensions extending TestInstantiationAwareExtension will receive an ExtensionContext that is scoped to the test class. Extensions may override the getTestInstantiationExtensionContextScope(...) method to receive an ExtensionContext that is scoped to the test method instead. Moreover, the junit.jupiter.extensions.testinstantiation.extensioncontextscope.default configuration parameter allows to change the default to TEST_METHOD for extensions returning DEFAULT from that method (as done by the default implementation).
Motivation
There is currently no way for an extension to signal that it needs an ExtensionContext scoped to the test class. For example, an extension may offer a configuration option to switch between test method/class scope and need to signal that by returning a corresponding enum constant.
Moreover, should an extension support both test class and test method scope, e.g. by returning DEFAULT, it might need to know which is actually used. While it may be possible to determine the scope by inspecting the supplied ExtensionContext, it would be preferable to avoid the guess work.
Deliverables
Context
TestInstantiationAwareExtensionandExtensionContextScopewere introduced in 5.12 to enable use cases such as field injection in nested test classes. For backward compatibility, by default, extensions extendingTestInstantiationAwareExtensionwill receive anExtensionContextthat is scoped to the test class. Extensions may override thegetTestInstantiationExtensionContextScope(...)method to receive anExtensionContextthat is scoped to the test method instead. Moreover, thejunit.jupiter.extensions.testinstantiation.extensioncontextscope.defaultconfiguration parameter allows to change the default toTEST_METHODfor extensions returningDEFAULTfrom that method (as done by the default implementation).Motivation
There is currently no way for an extension to signal that it needs an
ExtensionContextscoped to the test class. For example, an extension may offer a configuration option to switch between test method/class scope and need to signal that by returning a corresponding enum constant.Moreover, should an extension support both test class and test method scope, e.g. by returning
DEFAULT, it might need to know which is actually used. While it may be possible to determine the scope by inspecting the suppliedExtensionContext, it would be preferable to avoid the guess work.Deliverables
ExtensionContextScope.TEST_CLASSExtensionContext.getScope()or similarTEST_METHOD