Top Description Methods
org.junit.jupiter.api.extension

public Interface TestInstances

Annotations
@API
status:STABLE
since:5.7
Static Imports
org.apiguardian.api.API.Status.STABLE

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

Modifier and TypeMethod and Description
public <T> Optional<T>

Returns:

the first test instance of the required type; never null but potentially empty
findInstance
(Class<T>
the type to search for
requiredType
)

Find the first test instance that is an instance of the supplied required type, checking from innermost to outermost.

public List<Object>

Returns:

all test instances; never null, containing null, or empty
getAllInstances
()

Get all test instances, ordered from outermost to innermost.

public List<Object>

Returns:

the enclosing test instances; never null or containing null, but potentially empty
getEnclosingInstances
()

Get the enclosing test instances, excluding the innermost test instance, ordered from outermost to innermost.

public Object

Returns:

the innermost test instance; never null
getInnermostInstance
()

Get the innermost test instance.

Method Detail

findInstanceback to summary
public <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:Class<T>

the type to search for

Returns:Optional<T>

the first test instance of the required type; never null but potentially empty

getAllInstancesback to summary
public List<Object> getAllInstances()

Get all test instances, ordered from outermost to innermost.

Returns:List<Object>

all test instances; never null, containing null, or empty

getEnclosingInstancesback to summary
public List<Object> getEnclosingInstances()

Get the enclosing test instances, excluding the innermost test instance, ordered from outermost to innermost.

Returns:List<Object>

the enclosing test instances; never null or containing null, but potentially empty

getInnermostInstanceback to summary
public Object getInnermostInstance()

Get the innermost test instance.

The innermost instance is the one closest to the test method.

Returns:Object

the innermost test instance; never null