Skip to end of metadata
Go to start of metadata

How to direct test output to the console

By default, test output goes to target/surefire-reports/. If you'd like to see it on the console, add

to the command line.

To make this permanent, configure the Surefire plugin as follows:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
       <reportFormat>brief</reportFormat>
       <useFile>false</useFile>
   </configuration>
</plugin>

Or to set the properties without configuring the plugin use global property names:

<properties>
  <surefire.useFile>false</surefire.useFile>
</properties>

if you want to set the reportFormat it's global property name is surefire.reportFormat

How to skip all tests by default

Put this in your settings.xml:

     <!-- skip tests by default, but allow override on command line -->
     <profile>
       <id>skiptests</id>
       <activation>
         <property>
           <name>!maven.test.skip</name>
         </property>
       </activation>
       <properties>
         <maven.test.skip>true</maven.test.skip>
       </properties>
     </profile>

This will set maven.test.skip to true, as long as you don't set it on
the command line. The nice part about this technique is that it DOES
allow you to override it on the command line if you want to.

Surefire and the System Classloader

However you run Surefire (forked or not, with child delegation or not), the system classloader will not contain your test code. In
forked mode, it will only contain surefire and your testing framework. Surefire itself will create an isolated classloader that contains your
test code and its dependencies and run your tests from that classloader.

If you expect your code to work in anything but a basic Java application, do not depend on the system classloader.

Suggested individual changes to existing documentation

  • No labels

1 Comment

  1. Hi,

    How can we prevent the surefire plugin to generate the .txt and .xml files ?

    We use TestNG, Maven and Hudson to maintain our test suite. We use Testng reporting but hudson always seems to pick up numbers from the files that are generated by Maven.

    For example - Total tests - 3 , we retry failed tests using TestNG features.

    1. Hudson job kicks off
    2. Test 1 fails , we retry - Test 1 passes
    3. Test 2 passes
    4. Test 3 fails , retry 1 time, retry 2nd time & Test 3 passes

    Our testng report shows Total - 3, Pass - 3, Fail 0

    But TestSuite.txt, TEST-TestSuite.xml in target/surefire-reports show - Total - 5, Pass- 3, Fail - 2

    So basically maven counts each run of the test as a new test which messes up the numbers and the hudson job is yellow instead of blue.

    Any help is appreciated!

    Thanks