31

When I am running maven clean install it always executes all tests in src/test/java is there a way to skip all the tests, just to run simple build without any tests.

I want my tests to be in src/test/java but I want to tell maven to do not execute them. I've been looking for something like that on the internet but I did not manage to find the answer.

Is there a way to do this?

Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143

8 Answers8

56

Try with:

mvn clean install -DskipTests

Source here.

Amol
  • 1,084
  • 10
  • 20
jelies
  • 9,110
  • 5
  • 50
  • 65
20

You can also choose to use

mvn install -Dmaven.test.skip

From Maven website:

If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.

As is says you will not even compile the test sources.

maba
  • 47,113
  • 10
  • 108
  • 118
7

From http://maven.apache.org/plugins/maven-surefire-plugin/examples/skipping-test.html:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.2</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
Buhb
  • 7,088
  • 3
  • 24
  • 38
4

use this

mvn clean install -DskipTests

Eugene
  • 117,005
  • 15
  • 201
  • 306
4

My favorite way to manage when my tests run is to create a Maven variable called skip-tests and default it to true. Then you can use that variable like so:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.2</version>
    <configuration>
      <skipTests>${skip-tests}</skipTests>
    </configuration>
  </plugin>

This way, you can just pass in the variable at build time, -Dskip-tests=false, when you don't want them to run. This is most useful when you have integration and unit tests, and would like to run or disable both sets of tests with just one variable.

Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94
2

All the answers here are correct. To be precise,

-DskipTests - compiles the test classes, but skips running them,
-Dmaven.test.skip=true - skips compiling the test files and also does not run them

Krishna
  • 393
  • 2
  • 3
  • 18
0

We use Surefire for Unit tests, and Failsafe for Integration tests.

To skip all tests:

mvn clean package -DskipTests

To skip just Failsafe tests:

mvn clean package -DskipIT

To skip just Surefire, you need to explicitly call the integration-test goal of the Failsafe plugin, after compiling the test classes of course:

mvn clean test-compile failsafe:integration-test
wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
-1

I think simplest would be this : mvn clean package -Dmaven.skip.tests=true

I think this the approach to use as it does not make you change your pom, so does not have to make changes to the project.

jelies
  • 9,110
  • 5
  • 50
  • 65
Dhruvenkumar Shah
  • 520
  • 2
  • 10
  • 26