1.2.5.8 在扩展中维持状态
TestWatcher
defines the API for extensions that wish to process the results of test method executions. Specifically, a TestWatcher
will be invoked with contextual information for the following events.
testDisabled
: invoked after a disabled test method has been skippedtestSuccessful
: invoked after a test method has completed successfullytestAborted
: invoked after a test method has been abortedtestFailed
: invoked after a test method has failed
In contrast to the definition of "test method" presented in Test Classes and Methods, in this context test method refers to any
@Test
method or@TestTemplate
method (for example, a@RepeatedTest
or@ParameterizedTest
).
Extensions implementing this interface can be registered at the method level or at the class level. In the latter case they will be invoked for any contained test method including those in @Nested
classes.
Any instances of
ExtensionContext.Store.CloseableResource
stored in theStore
of the providedExtensionContext
will be closed before methods in this API are invoked (see Keeping State in Extensions). You can use the parent context’sStore
to work with such resources.