Class DynamicExtensionContext
- java.lang.Object
-
- org.junit.jupiter.engine.descriptor.DynamicExtensionContext
-
- All Implemented Interfaces:
AutoCloseable
,ExtensionContext
public class DynamicExtensionContext extends Object
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Optional<String>
getConfigurationParameter(String key)
Get the configuration parameter stored under the specifiedkey
.String
getDisplayName()
Get the display name for the current test or container.Optional<AnnotatedElement>
getElement()
Get theAnnotatedElement
corresponding to the current extension context, if available.Optional<Throwable>
getExecutionException()
Get the exception that was thrown during execution of the test or container associated with thisExtensionContext
, if available.Optional<ExtensionContext>
getParent()
Get the parent extension context, if available.ExtensionContext
getRoot()
Get the rootExtensionContext
.ExtensionContext.Store
getStore(ExtensionContext.Namespace namespace)
Get theExtensionContext.Store
for the suppliedExtensionContext.Namespace
.Set<String>
getTags()
Get the set of all tags for the current test or container.Optional<Class<?>>
getTestClass()
Get theClass
associated with the current test or container, if available.protected T
getTestDescriptor()
Optional<Object>
getTestInstance()
Get the test instance associated with the current test or container, if available.Optional<TestInstance.Lifecycle>
getTestInstanceLifecycle()
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.Optional<TestInstances>
getTestInstances()
Get the test instances associated with the current test or container, if available.Optional<Method>
getTestMethod()
Get theMethod
associated with the current test, if available.String
getUniqueId()
Get the unique ID of the current test or container.void
publishReportEntry(Map<String,String> values)
Publish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListener
in order to supply additional information to the reporting infrastructure.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, publishReportEntry, publishReportEntry
-
-
-
-
Method Detail
-
getElement
public Optional<AnnotatedElement> getElement()
Description copied from interface:ExtensionContext
Get theAnnotatedElement
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
orMethod
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.- Returns:
- an
Optional
containing theAnnotatedElement
; nevernull
but potentially empty - See Also:
ExtensionContext.getTestClass()
,ExtensionContext.getTestMethod()
-
getTestClass
public Optional<Class<?>> getTestClass()
Description copied from interface:ExtensionContext
Get theClass
associated with the current test or container, if available.- Returns:
- an
Optional
containing the class; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestClass()
-
getTestInstanceLifecycle
public Optional<TestInstance.Lifecycle> getTestInstanceLifecycle()
Description copied from interface:ExtensionContext
Get theTestInstance.Lifecycle
of the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instanceLifecycle
; nevernull
but potentially empty - See Also:
TestInstance
-
getTestInstance
public Optional<Object> getTestInstance()
Description copied from interface:ExtensionContext
Get the test instance associated with the current test or container, if available.- Returns:
- an
Optional
containing the test instance; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestInstance()
,ExtensionContext.getTestInstances()
-
getTestInstances
public Optional<TestInstances> getTestInstances()
Description copied from interface:ExtensionContext
Get the test instances associated with the current test or container, if available.While top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.
- Returns:
- an
Optional
containing the test instances; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestInstances()
-
getTestMethod
public Optional<Method> getTestMethod()
Description copied from interface:ExtensionContext
Get theMethod
associated with the current test, if available.- Returns:
- an
Optional
containing the method; nevernull
but potentially empty - See Also:
ExtensionContext.getRequiredTestMethod()
-
getExecutionException
public Optional<Throwable> getExecutionException()
Description copied from interface:ExtensionContext
Get the exception that was thrown during execution of the test or container associated with thisExtensionContext
, 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-levelExtension
. Similarly, if thisExtensionContext
represents a test class, the execution exception returned by this method can be any exception thrown in a@BeforeAll
orAfterAll
method or a class-levelExtension
.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.- Returns:
- an
Optional
containing the exception thrown; nevernull
but potentially empty if test execution has not (yet) resulted in an exception
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
getUniqueId
public String getUniqueId()
Description copied from interface:ExtensionContext
Get the unique ID of the current test or container.- Specified by:
getUniqueId
in interfaceExtensionContext
- Returns:
- the unique ID of the test or container; never
null
or blank
-
getDisplayName
public String getDisplayName()
Description copied from interface:ExtensionContext
Get the display name for the current test or container.The 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.
- Specified by:
getDisplayName
in interfaceExtensionContext
- Returns:
- the display name of the test or container; never
null
or blank
-
publishReportEntry
public void publishReportEntry(Map<String,String> values)
Description copied from interface:ExtensionContext
Publish a map of key-value pairs to be consumed by anorg.junit.platform.engine.EngineExecutionListener
in order to supply additional information to the reporting infrastructure.- Specified by:
publishReportEntry
in interfaceExtensionContext
- Parameters:
values
- the key-value pairs to be published; nevernull
; keys and values within entries in the map also must not benull
or blank- See Also:
ExtensionContext.publishReportEntry(String, String)
,ExtensionContext.publishReportEntry(String)
,EngineExecutionListener.reportingEntryPublished(org.junit.platform.engine.TestDescriptor, org.junit.platform.engine.reporting.ReportEntry)
-
getParent
public Optional<ExtensionContext> getParent()
Description copied from interface:ExtensionContext
Get the parent extension context, if available.- Specified by:
getParent
in interfaceExtensionContext
- Returns:
- an
Optional
containing the parent; nevernull
but potentially empty - See Also:
ExtensionContext.getRoot()
-
getRoot
public ExtensionContext getRoot()
Description copied from interface:ExtensionContext
Get the rootExtensionContext
.- Specified by:
getRoot
in interfaceExtensionContext
- Returns:
- the root extension context; never
null
but potentially thisExtensionContext
- See Also:
ExtensionContext.getParent()
-
getTestDescriptor
protected T getTestDescriptor()
-
getStore
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
Description copied from interface:ExtensionContext
Get theExtensionContext.Store
for the suppliedExtensionContext.Namespace
.Use
getStore(Namespace.GLOBAL)
to get the default, globalExtensionContext.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 theirclose()
methods.- Specified by:
getStore
in interfaceExtensionContext
- Parameters:
namespace
- theNamespace
to get the store for; nevernull
- Returns:
- the store in which to put and get objects for other invocations
working in the same namespace; never
null
- See Also:
ExtensionContext.Namespace.GLOBAL
-
getTags
public Set<String> getTags()
Description copied from interface:ExtensionContext
Get the set of all tags for the current test or container.Tags may be declared directly on the test element or inherited from an outer context.
- Specified by:
getTags
in interfaceExtensionContext
- Returns:
- the set of tags for the test or container; never
null
but potentially empty
-
getConfigurationParameter
public Optional<String> getConfigurationParameter(String key)
Description copied from interface:ExtensionContext
Get the configuration parameter stored under the specifiedkey
.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.- Specified by:
getConfigurationParameter
in interfaceExtensionContext
- Parameters:
key
- the key to look up; nevernull
or blank- Returns:
- an
Optional
containing the value; nevernull
but potentially empty - See Also:
System.getProperty(String)
,ConfigurationParameters
-
-