Java 当通过主类运行时,如何将junit日志打印到控制台?
我有以下代码:Java 当通过主类运行时,如何将junit日志打印到控制台?,java,intellij-idea,junit,Java,Intellij Idea,Junit,我有以下代码: public class CacheOnlyTestRunner { public static void main(String[] args) throws Exception { Request request = Request.method(Class.forName("linqmap.users.jms.UsersServerAccessCache"), "getUserFillsCac
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
java.lang.AssertionError:
预期:
但是:是吗
位于org.hamcrest.matcherasert.assertThat(matcherasert.java:20)
位于org.junit.Assert.assertThat(Assert.java:865)
位于org.junit.Assert.assertThat(Assert.java:832)
在
您必须编写一个应用程序,并在JUnitCore上注册它
JUnitCore core = new JUnitCore();
core.addListener(new YourListener());
Result result = core.run(request);
您可以看看JUnit的TextListener: