@API(status=EXPERIMENTAL, since="5.4") public interface TestWatcher extends Extension
TestWatcher
defines the API for Extensions
that
wish to process test results.
The methods in this API are called after a test has been skipped or
executed. Any CloseableResource
objects stored in the Store
of the supplied
ExtensionContext
will have already been closed before
methods in this API are invoked.
Please note that this API is currently only used to report the results of
@Test
methods and
@TestTemplate
methods (e.g.,
@RepeatedTest
and @ParameterizedTest
). Moreover, if there is a
failure at the class level — for example, an exception thrown by a
@BeforeAll
method — no test results will be reported.
Extensions implementing this API can be registered at any level.
In contrast to other Extension
APIs, a TestWatcher
is not
permitted to adversely influence the execution of tests. Consequently, any
exception thrown by a method in the TestWatcher
API will be logged at
WARNING
level and will not be allowed to propagate or fail test
execution.
Modifier and Type | Method and Description |
---|---|
default void |
testAborted(ExtensionContext context,
java.lang.Throwable cause)
Invoked after a test has been aborted.
|
default void |
testDisabled(ExtensionContext context,
java.util.Optional<java.lang.String> reason)
Invoked after a disabled test has been skipped.
|
default void |
testFailed(ExtensionContext context,
java.lang.Throwable cause)
Invoked after a test has failed.
|
default void |
testSuccessful(ExtensionContext context)
Invoked after a test has completed successfully.
|
default void testDisabled(ExtensionContext context, java.util.Optional<java.lang.String> reason)
The default implementation does nothing. Concrete implementations can override this method as appropriate.
context
- the current extension context; never null
reason
- the reason the test is disabled; never null
but
potentially emptydefault void testSuccessful(ExtensionContext context)
The default implementation does nothing. Concrete implementations can override this method as appropriate.
context
- the current extension context; never null
default void testAborted(ExtensionContext context, java.lang.Throwable cause)
The default implementation does nothing. Concrete implementations can override this method as appropriate.
context
- the current extension context; never null
cause
- the throwable responsible for the test being aborted; may be null
default void testFailed(ExtensionContext context, java.lang.Throwable cause)
The default implementation does nothing. Concrete implementations can override this method as appropriate.
context
- the current extension context; never null
cause
- the throwable that caused test failure; may be null