下面的代码是从http://junit.org/javadoc/4.9/org/junit/rules/TestWatcher.html修改的(几乎没有) 我希望看到一个通过和失败,就像在 @rule 中打印到控制台执行测试时,我什么也看不到。这让我相信我不明白这应该如何工作。如果有人可以解释为什么这不起作用,我将不胜感激。
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
public class SimpleWatcher {
private static String watchedLog;
@Rule
public TestWatcher watchman= new TestWatcher() {
@Override
protected void failed(Throwable t, Description d) {
watchedLog+= d + "\n";
System.out.println("Failed");
}
@Override
protected void succeeded(Description d) {
watchedLog+= d + " " + "success!\n";
System.out.println("Pass");
}
};
@Test
public void fails() {
fail();
}
@Test
public void succeeds() {
}
}