final class MethodExtensionContext extends AbstractExtensionContext<TestMethodTestDescriptor>
ExtensionContext.Namespace, ExtensionContext.Store| Modifier and Type | Field and Description |
|---|---|
private TestInstances |
testInstances |
private ThrowableCollector |
throwableCollector |
| Constructor and Description |
|---|
MethodExtensionContext(ExtensionContext parent,
EngineExecutionListener engineExecutionListener,
TestMethodTestDescriptor testDescriptor,
JupiterConfiguration configuration,
ThrowableCollector throwableCollector) |
| Modifier and Type | Method and Description |
|---|---|
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<java.lang.Class<?>> |
getTestClass()
Get the
Class associated with the current test or container,
if available. |
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<TestInstances> |
getTestInstances()
Get the test instances 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. |
(package private) void |
setTestInstances(TestInstances testInstances) |
close, getConfigurationParameter, getDisplayName, getParent, getRoot, getStore, getTags, getTestDescriptor, getUniqueId, publishReportEntryclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, publishReportEntry, publishReportEntryprivate final ThrowableCollector throwableCollector
private TestInstances testInstances
MethodExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestMethodTestDescriptor testDescriptor, JupiterConfiguration configuration, 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 empty{@code @TestInstance}public java.util.Optional<java.lang.Object> getTestInstance()
ExtensionContextOptional containing the test instance; never
null but potentially emptyExtensionContext.getRequiredTestInstance(),
ExtensionContext.getTestInstances()public java.util.Optional<TestInstances> getTestInstances()
ExtensionContextWhile top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.
Optional containing the test instances; never
null but potentially emptyExtensionContext.getRequiredTestInstances()void setTestInstances(TestInstances testInstances)
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 exception