Similar to JUnit4’s TestWatcher
this extension watches the test invocation without modifying it or interfering with it in any way. Instead, it just logs:
This extension uses java.util.logging.Logger
so it will either play nicely with your current logging solution or there will be a bridge to allow it to do so (e.g. jul-to-slf4j).
This extension is engaged by adding the @ExtendWith(WatcherExtension.class)
annotation to a test class.
@ExtendWith(WatcherExtension.class)
public class MyTest {
// entry, exit and elapsed time will be logged for every test in this test case
}
Example output (after bridging to SLF4J):
2017-11-15 17:17:03,945|[main]|INFO |o.g.j.e.watcher.WatcherExtension|Starting test [canGet]
2017-11-15 17:17:04,167|[main]|INFO |o.g.d.http.okhttp.OkHttpClient|Get from: http://host:1234/some/end/point
2017-11-15 17:17:04,201|[main]|INFO |o.g.j.e.watcher.WatcherExtension|Completed test [canGet] in 247ms