我有这段代码:
public class CacheOnlyTestRunner {
public static void main(String[] args) throws Exception {
Request request = Request.method(Class.forName("linqmap.users.jms.UsersServerAccessCache"),
"getUserFillsCacheWithAllPropertiesWhenOnlyFlagReadModeCacheIsEnabled");
Result result = new JUnitCore().run(request);
System.out.println(result.wasSuccessful() ? "test passed===" : "test failed===");
System.exit(result.wasSuccessful() ? 0 : 1);
//comment
}
}
我从终端进行了一次junit测试。它失败了。
当我在intellij中运行时,如何看到失败的断言文本?
我看到其他日志,但不是这个例子:
java.lang.AssertionError:
Expected: <2>
but: was <26>
<Click to see difference>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:865)
at org.junit.Assert.assertThat(Assert.java:832)
at
答案 0 :(得分:0)
您必须撰写RunListener并在JUnitCore
注册。
JUnitCore core = new JUnitCore();
core.addListener(new YourListener());
Result result = core.run(request);
您可以查看JUnit的TextListener:https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/internal/TextListener.java