Verwendung von @Regeln auf TestWatcher können Sie die Anzahl und viele andere Dinge wie den Methodennamen usw. notieren. Sie können diese Methoden außer Kraft setzen und .
@Override
public Statement apply(Statement base, Description description){
return super.apply(base, description);
}
@Override
protected void failed(Throwable e, Description description) {
failed.add(description);
LogUtil.error("[FAILED] "+description.getMethodName()+" [Test Failed]"+e.getMessage());
super.failed(e, description);
}
@Override
protected void finished(Description description) {
LogUtil.info("[FINISHED] "+description.getMethodName());
super.finished(description);
}
@Override
protected void skipped(AssumptionViolatedException e,Description description) {
LogUtil.error("[FAILED] Test Failed due to Assumption Voilation "+e.getMessage());
super.skipped(e,description);
}
@Override
protected void starting(Description description) {
LogUtil.info("-----------------------------------------------------------");
LogUtil.info("[STARTED] "+description.getMethodName());
super.starting(description);
}
@Override
protected void succeeded(Description description) {
passed.add(description);
LogUtil.info("[PASSED] "+description.getMethodName());
super.succeeded(description);
}
Verwenden Sie in Ihrem Junit-Testfall
@Rule
public TestRule watcher = new TestWatcherChild();