26

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 ?

pavel_kazlou
  • 1,995
  • 4
  • 28
  • 34

4 Answers4

35

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>
javabrett
  • 7,020
  • 4
  • 51
  • 73
orien
  • 2,130
  • 16
  • 20
  • 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? – pavel_kazlou Nov 18 '11 at 10:48
  • Yes. So you have your assertion message, exception message and stack trace right there on `stdout`. – orien Nov 18 '11 at 11:05
  • 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. – ArtOfWarfare Oct 21 '13 at 14:22
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.

Jim Bethancourt
  • 1,061
  • 11
  • 16
-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>
nakhodkin
  • 1,327
  • 1
  • 17
  • 27
Vishal
  • 1
  • 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](/help/how-to-answer). – Community Dec 16 '22 at 06:10
-12

try using bellow maven command

mvn clean install -DskipTests

-DskipTests compiles the tests, but skips running them

Derrick
  • 3,669
  • 5
  • 35
  • 50
Vipul Gulhane
  • 761
  • 11
  • 16