- All Superinterfaces:
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
TestInstanceFactorydefines the API for
Extensionsthat 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.
Extensions that implement
TestInstanceFactory must be registered
at the class level.
TestInstanceFactory is allowed to be registered for any
given test class. Registering multiple factories for any single test class
will result in an exception being thrown for all tests in that class, in any
subclass, and in any nested class. Note that any
registered in a superclass or
enclosing class (i.e., in the case of
@Nested test class) is inherited. It is therefore the
user's responsibility to ensure that only a single
is registered for any specific test class.
Consult the documentation in
Extension for details on
Method SummaryModifier and TypeMethodDescription
(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext)Callback for creating a test instance for the supplied context.
(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext) throws TestInstantiationExceptionCallback for creating a test instance for the supplied context.
ExtensionContextsupplied to a
TestInstanceFactorywill always return an empty
getTestInstance()since the test instance cannot exist before it has been created by a
TestInstanceFactoryor the framework itself.
factoryContext- the context for the test class to be instantiated; never
extensionContext- the current extension context; never
- the test instance; never
TestInstantiationException- if an error occurs while creating the test instance