Class MethodExtensionContext
- All Implemented Interfaces:
AutoCloseable,ExtensionContext
- Since:
- 5.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMethodExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestMethodTestDescriptor testDescriptor, JupiterConfiguration configuration, ThrowableCollector throwableCollector) -
Method Summary
Modifier and TypeMethodDescriptionGet theAnnotatedElementcorresponding to the current extension context, if available.Get the exception that was thrown during execution of the test or container associated with thisExtensionContext, if available.protected Node.ExecutionModeGet theClassassociated with the current test or container, if available.Get the test instance associated with the current test or container, if available.Get theTestInstance.Lifecycleof the test instance associated with the current test or container, if available.Get the test instances associated with the current test or container, if available.Get theMethodassociated with the current test, if available.(package private) voidsetTestInstances(TestInstances testInstances) Methods inherited from class org.junit.jupiter.engine.descriptor.AbstractExtensionContext
close, getConfigurationParameter, getConfigurationParameter, getDisplayName, getExecutionMode, getParent, getRoot, getStore, getTags, getTestDescriptor, getUniqueId, publishReportEntryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.ExtensionContext
getRequiredTestClass, getRequiredTestInstance, getRequiredTestInstances, getRequiredTestMethod, publishReportEntry, publishReportEntry
-
Field Details
-
throwableCollector
-
testInstances
-
-
Constructor Details
-
MethodExtensionContext
MethodExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestMethodTestDescriptor testDescriptor, JupiterConfiguration configuration, ThrowableCollector throwableCollector)
-
-
Method Details
-
getElement
Description copied from interface:ExtensionContextGet theAnnotatedElementcorresponding 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
ClassorMethodreference.Favor this method over more specific methods whenever the
AnnotatedElementAPI suits the task at hand — for example, when looking up annotations regardless of concrete element type.- Returns:
- an
Optionalcontaining theAnnotatedElement; nevernullbut potentially empty - See Also:
-
getTestClass
Description copied from interface:ExtensionContextGet theClassassociated with the current test or container, if available.- Returns:
- an
Optionalcontaining the class; nevernullbut potentially empty - See Also:
-
getTestInstanceLifecycle
Description copied from interface:ExtensionContextGet theTestInstance.Lifecycleof the test instance associated with the current test or container, if available.- Returns:
- an
Optionalcontaining the test instanceLifecycle; nevernullbut potentially empty - See Also:
-
getTestInstance
Description copied from interface:ExtensionContextGet the test instance associated with the current test or container, if available.- Returns:
- an
Optionalcontaining the test instance; nevernullbut potentially empty - See Also:
-
getTestInstances
Description copied from interface:ExtensionContextGet 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
Optionalcontaining the test instances; nevernullbut potentially empty - See Also:
-
setTestInstances
-
getTestMethod
Description copied from interface:ExtensionContextGet theMethodassociated with the current test, if available.- Returns:
- an
Optionalcontaining the method; nevernullbut potentially empty - See Also:
-
getExecutionException
Description copied from interface:ExtensionContextGet 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
TestExecutionExceptionHandlerAPI.Unlike the exception passed to a
TestExecutionExceptionHandler, an execution exception returned by this method can be any exception thrown during the invocation of a@Testmethod, its surrounding@BeforeEachand@AfterEachmethods, or a test-levelExtension. Similarly, if thisExtensionContextrepresents a test class, the execution exception returned by this method can be any exception thrown in a@BeforeAllorAfterAllmethod 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
Optionalcontaining the exception thrown; nevernullbut potentially empty if test execution has not (yet) resulted in an exception
-
getPlatformExecutionMode
- Specified by:
getPlatformExecutionModein classAbstractExtensionContext<TestMethodTestDescriptor>
-