junit TestWatcher似乎没有意识到测试已经运行

时间:2013-05-30 10:41:24

标签: java junit

以下代码({勉强)从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() {
    }
 }

0 个答案:

没有答案