Interface TestInstanceFactory
-
- All Superinterfaces:
Extension
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @API(status=EXPERIMENTAL, since="5.3") public interface TestInstanceFactory extends Extension
TestInstanceFactory
defines the API forExtensions
that wish to create test instances.Common use cases include creating test instances with special construction requirements or acquiring the test instance from a dependency injection framework.
Only one
TestInstanceFactory
is allowed to be registered for each test class in the test class hierarchy, with lower level factories overriding factories registered at higher levels in the hierarchy. Registering multiple factories for any single test class will result in an exception being thrown for all the tests in that test class and any nested test classes.Extensions that implement
TestInstanceFactory
must be registered at the class level.Constructor Requirements
Consult the documentation in
Extension
for details on constructor requirements.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Object
createTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext)
Callback for creating a test instance for the supplied context.
-
-
-
Method Detail
-
createTestInstance
Object createTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext) throws TestInstantiationException
Callback for creating a test instance for the supplied context.Note: the
ExtensionContext
supplied to aTestInstanceFactory
will always return an emptyOptional
value fromgetTestInstance()
since the test instance cannot exist before it has been created by aTestInstanceFactory
or the framework itself.- Parameters:
factoryContext
- the context for the test class to be instantiated; nevernull
extensionContext
- the current extension context; nevernull
- Returns:
- the test instance; never
null
- Throws:
TestInstantiationException
- if an error occurs while creating the test instance
-
-