Output failed test details to stdout using maven surefire
Asked Answered
R

4

27

When I run my build using maven 2

mvn clean install

my tests are run by surefire plug-in. 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. 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 ?

Ranking answered 18/11, 2011 at 9:31 Comment(0)
O
38

I find there's way too much output produced on stdout to be useful. Try leaving the HTML report open in your browser. After running your tests just refresh the page. Have a look at target/surefire-reports/index.html.

To output test results to stdout rather than a file use the following command:

mvn test -Dsurefire.useFile=false

Or to configure in your pom.xml add the following to your plugins section.

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.10</version>
  <configuration>
    <useFile>false</useFile>
  </configuration>
</plugin>
Oolite answered 18/11, 2011 at 9:53 Comment(3)
Thanks! Missed that option. So the only thing which is being output to console instead of file is that brief report, while all the other staff like xml, html reports are still being produced?Ranking
Yes. So you have your assertion message, exception message and stack trace right there on stdout.Oolite
That command doesn't seem to always work for me... it worked the first time, I fixed the issues, I hit the up arrow and ran it again, but the next time I spat out a message about needing to check target/surefire-reports again, without the contents of the file.Westwardly
T
0

It's possible you may be using an older version of 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.

Tropine answered 16/1, 2019 at 15:18 Comment(0)
B
-1

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. 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>
Bagworm answered 13/12, 2022 at 4:18 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Egger
I
-12

try using bellow maven command

mvn clean install -DskipTests

-DskipTests compiles the tests, but skips running them

Inkle answered 10/7, 2018 at 4:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.