当前位置: 首页 > 文档资料 > JUnit 5 用户指南 >

1.2.5.8 在扩展中维持状态

优质
小牛编辑
127浏览
2023-12-01

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 skipped
  • testSuccessful: invoked after a test method has completed successfully
  • testAborted: invoked after a test method has been aborted
  • testFailed: 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 the Store of the provided ExtensionContext will be closed before methods in this API are invoked (see Keeping State in Extensions). You can use the parent context’s Store to work with such resources.