ExtensionContext@API(status=INTERNAL, since="5.0") public final class ClassExtensionContext extends java.lang.Object
ExtensionContext.Namespace, ExtensionContext.Store| Constructor | Description |
|---|---|
ClassExtensionContext(ExtensionContext parent,
EngineExecutionListener engineExecutionListener,
ClassTestDescriptor testDescriptor,
TestInstance.Lifecycle lifecycle,
ConfigurationParameters configurationParameters,
ThrowableCollector throwableCollector) |
|
ClassExtensionContext(ExtensionContext parent,
EngineExecutionListener engineExecutionListener,
ClassTestDescriptor testDescriptor,
ConfigurationParameters configurationParameters,
ThrowableCollector throwableCollector) |
Create a new
ClassExtensionContext with TestInstance.Lifecycle.PER_METHOD. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
java.util.Optional<java.lang.String> |
getConfigurationParameter(java.lang.String key) |
Get the configuration parameter stored under the specified
key. |
java.lang.String |
getDisplayName() |
Get the display name for the current test or container.
|
java.util.Optional<java.lang.reflect.AnnotatedElement> |
getElement() |
Get the
AnnotatedElement corresponding to the current extension
context, if available. |
java.util.Optional<java.lang.Throwable> |
getExecutionException() |
Get the exception that was thrown during execution of the test or container
associated with this
ExtensionContext, if available. |
java.util.Optional<ExtensionContext> |
getParent() |
Get the parent extension context, if available.
|
ExtensionContext |
getRoot() |
Get the root
ExtensionContext. |
ExtensionContext.Store |
getStore(ExtensionContext.Namespace namespace) |
Get the
ExtensionContext.Store for the supplied ExtensionContext.Namespace. |
java.util.Set<java.lang.String> |
getTags() |
Get the set of all tags for the current test or container.
|
java.util.Optional<java.lang.Class<?>> |
getTestClass() |
Get the
Class associated with the current test or container,
if available. |
protected T |
getTestDescriptor() |
|
java.util.Optional<java.lang.Object> |
getTestInstance() |
Get the test instance associated with the current test or container,
if available.
|
java.util.Optional<TestInstance.Lifecycle> |
getTestInstanceLifecycle() |
Get the
TestInstance.Lifecycle of the test
instance associated with the current test or container, if available. |
java.util.Optional<java.lang.reflect.Method> |
getTestMethod() |
Get the
Method associated with the current test, if available. |
java.lang.String |
getUniqueId() |
Get the unique ID of the current test or container.
|
void |
publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values) |
Publish a map of key-value pairs to be consumed by an
org.junit.platform.engine.EngineExecutionListener. |
getRequiredTestClass, getRequiredTestInstance, getRequiredTestMethod, publishReportEntrypublic ClassExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, ClassTestDescriptor testDescriptor, ConfigurationParameters configurationParameters, ThrowableCollector throwableCollector)
ClassExtensionContext with TestInstance.Lifecycle.PER_METHOD.public ClassExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, ClassTestDescriptor testDescriptor, TestInstance.Lifecycle lifecycle, ConfigurationParameters configurationParameters, ThrowableCollector throwableCollector)
public java.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
ExtensionContextAnnotatedElement corresponding to the current extension
context, if available.
For example, if the current extension context encapsulates a test
class, test method, test factory method, or test template method, the
annotated element will be the corresponding Class or Method
reference.
Favor this method over more specific methods whenever the
AnnotatedElement API suits the task at hand — for example,
when looking up annotations regardless of concrete element type.
Optional containing the AnnotatedElement;
never null but potentially emptyExtensionContext.getTestClass(),
ExtensionContext.getTestMethod()public java.util.Optional<java.lang.Class<?>> getTestClass()
ExtensionContextClass associated with the current test or container,
if available.Optional containing the class; never null but
potentially emptyExtensionContext.getRequiredTestClass()public java.util.Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()
ExtensionContextTestInstance.Lifecycle of the test
instance associated with the current test or container, if available.Optional containing the test instance Lifecycle;
never null but potentially emptyTestInstancepublic java.util.Optional<java.lang.Object> getTestInstance()
ExtensionContextOptional containing the test instance; never
null but potentially emptyExtensionContext.getRequiredTestInstance()public java.util.Optional<java.lang.reflect.Method> getTestMethod()
ExtensionContextMethod associated with the current test, if available.Optional containing the method; never null but
potentially emptyExtensionContext.getRequiredTestMethod()public java.util.Optional<java.lang.Throwable> getExecutionException()
ExtensionContextExtensionContext, if available.
This method is typically used for logging and tracing purposes. If you
wish to actually handle an exception thrown during test execution,
implement the TestExecutionExceptionHandler API.
Unlike the exception passed to a TestExecutionExceptionHandler,
an execution exception returned by this method can be any
exception thrown during the invocation of a @Test method, its
surrounding @BeforeEach and @AfterEach methods, or a
test-level Extension. Similarly, if this ExtensionContext
represents a test class, the execution exception returned by
this method can be any exception thrown in a @BeforeAll or
AfterAll method or a class-level Extension.
Note, however, that this method will never return an exception
swallowed by a TestExecutionExceptionHandler. Furthermore, if
multiple exceptions have been thrown during test execution, the exception
returned by this method will be the first such exception with all
additional exceptions suppressed in the first one.
Optional containing the exception thrown; never
null but potentially empty if test execution has not (yet)
resulted in an exceptionpublic void close()
close in interface java.lang.AutoCloseablepublic java.lang.String getUniqueId()
ExtensionContextgetUniqueId in interface ExtensionContextnull or blankpublic java.lang.String getDisplayName()
ExtensionContextThe display name is either a default name or a custom name configured
via @DisplayName.
For details on default display names consult the Javadoc for
TestInfo.getDisplayName().
Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
getDisplayName in interface ExtensionContextnull or blankpublic void publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
ExtensionContextorg.junit.platform.engine.EngineExecutionListener.publishReportEntry in interface ExtensionContextvalues - the key-value pairs to be published; never null;
keys and values within entries in the map also must not be
null or blankpublic java.util.Optional<ExtensionContext> getParent()
ExtensionContextgetParent in interface ExtensionContextOptional containing the parent; never null but
potentially emptyExtensionContext.getRoot()public ExtensionContext getRoot()
ExtensionContextExtensionContext.getRoot in interface ExtensionContextnull but potentially
this ExtensionContextExtensionContext.getParent()protected T getTestDescriptor()
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
ExtensionContextExtensionContext.Store for the supplied ExtensionContext.Namespace.
Use getStore(Namespace.GLOBAL) to get the default, global ExtensionContext.Namespace.
A store is bound to its extension context lifecycle. When an extension
context lifecycle ends it closes its associated store. All stored values
that are instances of ExtensionContext.Store.CloseableResource are
notified by invoking their close() methods.
getStore in interface ExtensionContextnamespace - the Namespace to get the store for; never nullnullExtensionContext.Namespace.GLOBALpublic java.util.Set<java.lang.String> getTags()
ExtensionContextTags may be declared directly on the test element or inherited from an outer context.
getTags in interface ExtensionContextnull but
potentially emptypublic java.util.Optional<java.lang.String> getConfigurationParameter(java.lang.String key)
ExtensionContextkey.
If no such key is present in the ConfigurationParameters for
the JUnit Platform, an attempt will be made to look up the value as a
JVM system property. If no such system property exists, an attempt will
be made to look up the value in the JUnit Platform properties file.
getConfigurationParameter in interface ExtensionContextkey - the key to look up; never null or blankOptional containing the value; never null
but potentially emptySystem.getProperty(String),
ConfigurationParameters