Reputation:
I have some unit tests in my application. A I need to skip prat of them. In pom.xml I have defined if test has specific class - then skip it.
<profile>
<id>skip-unit-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<excludes>
<exclude>**/*.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
So, if I do package -Pskip-unit-tests
everything works, but if I do clean compile -Pskip-unit-tests test
then maven executes them. What is wrong with last command?
Upvotes: 0
Views: 2403
Reputation: 48055
I tested your profile and there is nothing wrong with it.
Normal run without profile:
iMac:Q13257987 maba$ mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Q13257987-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q13257987 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /Users/maba/Development/stackoverflow/java/Q13257987/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q13257987 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ Q13257987 --- [INFO] Surefire report directory: /Users/maba/Development/stackoverflow/java/Q13257987/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.stackoverflow.OrderTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ Q13257987 --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.655s [INFO] Finished at: Tue Nov 06 22:51:52 CET 2012 [INFO] Final Memory: 4M/81M [INFO] ------------------------------------------------------------------------
Result: One test was run
Run package with profile:
iMac:Q13257987 maba$ mvn package -Pskip-unit-tests [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Q13257987-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q13257987 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /Users/maba/Development/stackoverflow/java/Q13257987/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q13257987 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.11:test (default-test) @ Q13257987 --- [INFO] Surefire report directory: /Users/maba/Development/stackoverflow/java/Q13257987/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ Q13257987 --- [INFO] Building jar: /Users/maba/Development/stackoverflow/java/Q13257987/target/Q13257987-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.609s [INFO] Finished at: Tue Nov 06 22:49:24 CET 2012 [INFO] Final Memory: 4M/81M [INFO] ------------------------------------------------------------------------
Result: No tests were run
Run clean compile test with profile:
iMac:Q13257987 maba$ mvn clean compile -Pskip-unit-tests test [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Q13257987-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ Q13257987 --- [INFO] Deleting /Users/maba/Development/stackoverflow/java/Q13257987/target [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q13257987 --- [INFO] Compiling 1 source file to /Users/maba/Development/stackoverflow/java/Q13257987/target/classes [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q13257987 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Q13257987 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /Users/maba/Development/stackoverflow/java/Q13257987/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q13257987 --- [INFO] Compiling 1 source file to /Users/maba/Development/stackoverflow/java/Q13257987/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.11:test (default-test) @ Q13257987 --- [INFO] Surefire report directory: /Users/maba/Development/stackoverflow/java/Q13257987/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Results : Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.676s [INFO] Finished at: Tue Nov 06 22:54:44 CET 2012 [INFO] Final Memory: 8M/81M [INFO] ------------------------------------------------------------------------
Result: No tests were run
So to conclude your profile setup works.
That said, I think you should use mvn package -DskipTests
instead which is the easiest way to skip all tests.
If you on the other hand want to skip just some tests you can use your profile setup but I would rather suggest that you use JUnit Categories. The categories can be selected directly in the maven-surefire-plugin
configuration.
Upvotes: 0
Reputation: 7980
The option skipTests
does the job:
mvn clean install -DskipTests
This resolves all the test dependencies, compiles the tests, but prevents their execution. If you with to also skip their compilation (not a good idea!), use this:
mvn clean install -Dmaven.test.skip
BTW. there is no option to avoid resolution of test dependencies. Above options are implemented inside the surefire plugin, and it is executed after deps are resolved.
More about skipping tests in the documentation for maven-surefire-plugin.
Upvotes: 2
Reputation: 5005
According to the maven lifecycle (see here) tests are not run until after compile but are run before package. So I suspect your configuration is not actually doing what you think.
Upvotes: 0