[英]Output failed test details to stdout using maven surefire
When I run my build using maven 2当我使用 Maven 2 运行构建时
mvn clean install
my tests are run by surefire plug-in.我的测试是由 surefire 插件运行的。 In case test failed I get the following output:
如果测试失败,我会得到以下输出:
Results :
Failed tests:
test1(com.my.MyClassTest)
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to /home/user/myproject/mymodule/target/surefire-reports for the individual test results.
To get the details about the problem I have to go and check surefire reports folder.要获得有关问题的详细信息,我必须去检查 surefire 报告文件夹。 Doing this every time my tests fail becomes annoying.
每次我的测试失败时都这样做很烦人。 Is there any way I can get those details (assert message + exception + stack trace) right here on the stdout?
有什么办法可以在标准输出上获取这些详细信息(断言消息+异常+堆栈跟踪)?
I find there's way too much output produced on stdout
to be useful.我发现在
stdout
上产生的stdout
太多而stdout
。 Try leaving the HTML report open in your browser.尝试在浏览器中打开 HTML 报告。 After running your tests just refresh the page.
运行测试后只需刷新页面。 Have a look at
target/surefire-reports/index.html
.看看
target/surefire-reports/index.html
。
To output test results to stdout
rather than a file use the following command:要将测试结果输出到
stdout
而不是文件,请使用以下命令:
mvn test -Dsurefire.useFile=false
Or to configure in your pom.xml
add the following to your plugins
section.或者在您的
pom.xml
进行配置,将以下内容添加到您的plugins
部分。
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<useFile>false</useFile>
</configuration>
</plugin>
It's possible you may be using an older version of Surefire.您可能正在使用旧版本的 Surefire。 I have found that newer versions produce more useful output on the console.
我发现较新的版本会在控制台上产生更有用的输出。
If you only want to see failing tests or tests with errors and only see errors in the build, you can pass the -q argument to your Maven build command.如果您只想查看失败的测试或有错误的测试并且只查看构建中的错误,您可以将 -q 参数传递给您的 Maven 构建命令。
please check your version of jacoco plugin is compatible with jdk or not: i was getting similar issue, test cases were passing but it was failing while building project.请检查您的 jacoco 插件版本是否与 jdk 兼容:我遇到了类似的问题,测试用例通过了但在构建项目时失败了。 so upgraded version worked for me:
所以升级版本对我有用:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
try using bellow maven command尝试使用波纹管 maven 命令
mvn clean install -DskipTests
-DskipTests
compiles the tests, but skips running them -DskipTests
编译测试,但跳过运行它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.