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

public Interface ExtensionContext

Annotations
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .API.Status.INTERNAL, .API.Status.MAINTAINED, .API.Status.STABLE

ExtensionContext encapsulates the context in which the current test or container is being executed.

Extensions are provided an instance of ExtensionContext to perform their work.

This interface is not intended to be implemented by clients.

Since
5.0
See Also
Store, Namespace

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ExtensionContext.Namespace

A Namespace is used to provide a scope for data saved by extensions within a Store.

public static interface
ExtensionContext.Store

Store provides methods for extensions to save and retrieve data.

public static enum
ExtensionContext.StoreScope

StoreScope is an enumeration of the different scopes for Store instances.

Method Summary

Modifier and TypeMethod and Description
public Optional<String>

Returns:

an Optional containing the value; never null but potentially empty
getConfigurationParameter
(String
the key to look up; never null or blank
key
)

Get the configuration parameter stored under the specified key.

public <T> Optional<T>

Returns:

an Optional containing the value; never null but potentially empty
getConfigurationParameter
(String
the key to look up; never null or blank
key
,
Function<? super String, ? extends @Nullable T>
the transformer to apply in case a value is found; never null
transformer
)

Get and transform the configuration parameter stored under the specified key using the specified transformer.

public String

Returns:

the display name of the test or container; never null or blank
getDisplayName
()

Get the display name for the current test or container.

public Optional<AnnotatedElement>

Returns:

an Optional containing the AnnotatedElement; never null but potentially empty
getElement
()

Get the AnnotatedElement corresponding to the current extension context, if available.

public List<Class<?>>

Returns:

an empty list if there is no class associated with the current test or container or when it is not nested; otherwise, a list containing the enclosing test classes in order from outermost to innermost; never null
getEnclosingTestClasses
()

Get the enclosing test classes of the current test or container.

public ExecutableInvoker
getExecutableInvoker()

Get an ExecutableInvoker to invoke methods and constructors with support for dynamic resolution of parameters.

public Optional<Throwable>

Returns:

an Optional containing the exception thrown; never null but potentially empty if test execution has not (yet) resulted in an exception
getExecutionException
()

Get the exception that was thrown during execution of the test or container associated with this ExtensionContext, if available.

public ExecutionMode

Returns:

the ExecutionMode of the test; never null
getExecutionMode
()

Get the ExecutionMode associated with the current test or container.

public Optional<ExtensionContext>

Returns:

an Optional containing the parent; never null but potentially empty
getParent
()

Get the parent extension context, if available.

public default Class<?>

Returns:

the test class; never null
getRequiredTestClass
()

Get the required Class associated with the current test or container.

public default Object

Returns:

the test instance; never null
getRequiredTestInstance
()

Get the required test instance associated with the current test or container.

public default TestInstances

Returns:

the test instances; never null
getRequiredTestInstances
()

Get the required test instances associated with the current test or container.

public default Method

Returns:

the test method; never null
getRequiredTestMethod
()

Get the required Method associated with the current test or container.

public ExtensionContext

Returns:

the root extension context; never null but potentially this ExtensionContext
getRoot
()

Get the root ExtensionContext.

public ExtensionContext.Store

Returns:

the store in which to put and get objects for other invocations working in the same namespace; never null
getStore
(ExtensionContext.Namespace
the Namespace to get the store for; never null
namespace
)

Get the Store for the supplied Namespace.

public ExtensionContext.Store
getStore(ExtensionContext.StoreScope scope, ExtensionContext.Namespace namespace)

Returns the store for supplied scope and namespace.

public Set<String>

Returns:

the set of tags for the test or container; never null but potentially empty
getTags
()

Get the set of all tags for the current test or container.

public Optional<Class<?>>

Returns:

an Optional containing the class; never null but potentially empty
getTestClass
()

Get the Class associated with the current test or container, if available.

public Optional<Object>

Returns:

an Optional containing the test instance; never null but potentially empty
getTestInstance
()

Get the test instance associated with the current test or container, if available.

public Optional<TestInstance.Lifecycle>

Returns:

an Optional containing the test instance Lifecycle; never null but potentially empty
getTestInstanceLifecycle
()

Get the Lifecycle of the test instance associated with the current test or container, if available.

public Optional<TestInstances>

Returns:

an Optional containing the test instances; never null but potentially empty
getTestInstances
()

Get the test instances associated with the current test or container, if available.

public Optional<Method>

Returns:

an Optional containing the method; never null but potentially empty
getTestMethod
()

Get the Method associated with the current test, if available.

public String

Returns:

the unique ID of the test or container; never null or blank
getUniqueId
()

Get the unique ID of the current test or container.

public void
publishDirectory(String
the name of the directory to be published; never null or blank and must not contain any path separators
name
,
ThrowingConsumer<Path>
the action to be executed to write to the directory; never null
action
)

Publish a directory with the supplied name written by the supplied action and attach it to the current test or container.

public default void
publishFile(String
the name of the file to be published; never null or blank and must not contain any path separators
name
,
MediaType
the media type of the file; never null; use org.junit.jupiter.api.extension.MediaType#APPLICATION_OCTET_STREAM if unknown
mediaType
,
ThrowingConsumer<Path>
the action to be executed to write the file; never null
action
)
Deprecated for removal since 5.14. Use publishFile(String, MediaType, ThrowingConsumer) instead.

Publish a file with the supplied name written by the supplied action and attach it to the current test or container.

public void
publishFile(String
the name of the file to be attached; never null or blank and must not contain any path separators
name
,
MediaType
the media type of the file; never null; use MediaType#APPLICATION_OCTET_STREAM if unknown
mediaType
,
ThrowingConsumer<Path>
the action to be executed to write the file; never null
action
)

Publish a file with the supplied name written by the supplied action and attach it to the current test or container.

public void
publishReportEntry(Map<String, String>
the key-value pairs to be published; never null; keys and values within entries in the map also must not be null or blank
map
)

Publish a map of key-value pairs to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

public default void
publishReportEntry(String
the key of the published pair; never null or blank
key
,
String
the value of the published pair; never null or blank
value
)

Publish the specified key-value pair to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.

public default void
publishReportEntry(String
the value to be published; never null or blank
value
)

Publish the specified value to be consumed by an org.junit.platform.engine.EngineExecutionListener in order to supply additional information to the reporting infrastructure.