Package org.junit.jupiter.api.extension
Interface TestInstances
-
- All Known Implementing Classes:
DefaultTestInstances
@API(status=EXPERIMENTAL, since="5.4") public interface TestInstances
TestInstances
encapsulates the test instances of a test.While top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.
- Since:
- 5.4
- See Also:
ExtensionContext.getTestInstances()
,ExtensionContext.getRequiredTestInstances()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Optional<T>
findInstance(Class<T> requiredType)
Find the first test instance that is an instance of the supplied required type, checking from innermost to outermost.List<Object>
getAllInstances()
Get all test instances, ordered from outermost to innermost.List<Object>
getEnclosingInstances()
Get the enclosing test instances, excluding the innermost test instance, ordered from outermost to innermost.Object
getInnermostInstance()
Get the innermost test instance.
-
-
-
Method Detail
-
getInnermostInstance
Object getInnermostInstance()
Get the innermost test instance.The innermost instance is the one closest to the test method.
- Returns:
- the innermost test instance; never
null
-
getEnclosingInstances
List<Object> getEnclosingInstances()
Get the enclosing test instances, excluding the innermost test instance, ordered from outermost to innermost.- Returns:
- the enclosing test instances; never
null
or containingnull
, but potentially empty
-
getAllInstances
List<Object> getAllInstances()
Get all test instances, ordered from outermost to innermost.- Returns:
- all test instances; never
null
, containingnull
, or empty
-
findInstance
<T> Optional<T> findInstance(Class<T> requiredType)
Find the first test instance that is an instance of the supplied required type, checking from innermost to outermost.- Parameters:
requiredType
- the type to search for- Returns:
- the first test instance of the required type; never
null
but potentially empty
-
-