Reputation: 23413
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?
Upvotes: 32
Views: 65229
Reputation: 9290
Try with:
mvn clean install -DskipTests
Source Maven Surefire Plugin - Skipping Tests.
Upvotes: 60
Reputation: 473
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
Upvotes: 3
Reputation: 528
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.
Upvotes: -1
Reputation: 6934
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
Upvotes: 0
Reputation: 22899
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.
Upvotes: 4
Reputation: 48105
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.
Upvotes: 22
Reputation: 7149
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>
Upvotes: 8