2

Maven: how to skip the tests

 2 years ago
source link: https://marco.dev/maven-skip-tests
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Sometimes unit test are seem placed there only to bother us, tipically under stress.

What to do if we want quickly skip maven tests to test-drive an 'unofficial' new feature,

Don't build the tests

-Dmaven.test.skip=true or -Dmaven.test.skip
This instruction doesn't compile the tests.

You can add it to your maven build with:

<properties> 
    <maven.test.skip>true</maven.test.skip> 
</properties> 

You can use it with the command line:

$ mvn package -Dmaven.test.skip=true

Surefire plugin: Build the tests but don't execute them

This seems to be the first solution we try when we want to skip the tests (maybe because we have to type less), but often we have errors because the tests not started but they are compiled and it requires the Surefire plugin.

mvn install -DskipTests

You can add it to your project:

<project> 
  [...] 
  <build> 
    <plugins> 
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>${surefire.version}</version> 
        <configuration> 
          <skipTests>true</skipTests> 
        </configuration> 
      </plugin> 
    </plugins> 
  </build> 
</project> 

Surefire plugin: skip compiling the tests

This is equivalent to the first solution, the test are not build or executed.

mvn install -Dmaven.test.skip=true

Deep dive

Surefire gives you a lot of control in the management of the tests. You can run only one test or exclude some test according to a pattern.

If you are implementing a testing strategy for your Java project it's worth to look at the Surefire examples: https://maven.apache.org/surefire/maven-surefire-plugin/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK