简体   繁体   English

使用 maven surefire 将失败的测试详细信息输出到标准输出

[英]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.

相关问题 如何在 Maven surefire 中查看逐个测试的 stdout/stderr - How to see test-by-test stdout/stderr in Maven surefire 在Maven Surefire插件中获取失败测试的值 - Get values of a failed test in Maven Surefire Plugin 详细说明 maven 可靠测试 output - Less Verbose maven surefire test output Maven Surefire 测试失败:不支持 class 文件主要版本 61 - Maven Surefire test failed: Unsupported class file major version 61 如何在 maven surefire 单元测试中读取控制台输出 - How to read console output in maven surefire unit test 问题是使用测试 maven,显示此错误 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) - Issue is using test maven, this error is displayed Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) Maven原型:org.apache.maven.plugins:maven-surefire-plugin:2.20.1:测试失败:NullPointerException - Maven archetype: org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed.: NullPointerException 无法在不使用maven-surfire-plugin和测试的情况下执行目标org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test without using maven-surfire-plugin and tests Maven Surefire Junit测试套件 - Maven Surefire Junit test suite Maven Surefire 未执行测试阶段 - Maven Surefire not executing test phase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM