Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当通过主类运行时,如何将junit日志打印到控制台?_Java_Intellij Idea_Junit - Fatal编程技术网

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: