Class TestTemplateExtensionContext
- java.lang.Object
-
- org.junit.jupiter.engine.descriptor.AbstractExtensionContext<TestTemplateTestDescriptor>
-
- org.junit.jupiter.engine.descriptor.TestTemplateExtensionContext
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ExtensionContext
final class TestTemplateExtensionContext extends AbstractExtensionContext<TestTemplateTestDescriptor>
- 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 Modifier and Type Field Description private TestInstancestestInstances
-
Constructor Summary
Constructors Constructor Description TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, TestInstances testInstances)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.lang.reflect.AnnotatedElement>getElement()Get theAnnotatedElementcorresponding 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 thisExtensionContext, if available.java.util.Optional<java.lang.Class<?>>getTestClass()Get theClassassociated 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 theTestInstance.Lifecycleof 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 theMethodassociated with the current test, if available.-
Methods inherited from class org.junit.jupiter.engine.descriptor.AbstractExtensionContext
close, getConfigurationParameter, getConfigurationParameter, getDisplayName, getParent, getRoot, getStore, getTags, getTestDescriptor, getUniqueId, publishReportEntry
-
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
-
-
-
-
Field Detail
-
testInstances
private final TestInstances testInstances
-
-
Constructor Detail
-
TestTemplateExtensionContext
TestTemplateExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, TestTemplateTestDescriptor testDescriptor, JupiterConfiguration configuration, TestInstances testInstances)
-
-
Method Detail
-
getElement
public java.util.Optional<java.lang.reflect.AnnotatedElement> 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:
ExtensionContext.getTestClass(),ExtensionContext.getTestMethod()
-
getTestClass
public java.util.Optional<java.lang.Class<?>> 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:
ExtensionContext.getRequiredTestClass()
-
getTestInstanceLifecycle
public java.util.Optional<TestInstance.Lifecycle> 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:
TestInstance
-
getTestInstance
public java.util.Optional<java.lang.Object> 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:
ExtensionContext.getRequiredTestInstance(),ExtensionContext.getTestInstances()
-
getTestInstances
public java.util.Optional<TestInstances> 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:
ExtensionContext.getRequiredTestInstances()
-
getTestMethod
public java.util.Optional<java.lang.reflect.Method> getTestMethod()
Description copied from interface:ExtensionContextGet theMethodassociated with the current test, if available.- Returns:
- an
Optionalcontaining the method; nevernullbut potentially empty - See Also:
ExtensionContext.getRequiredTestMethod()
-
getExecutionException
public java.util.Optional<java.lang.Throwable> 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
-
-