To enable or disable unit tests for the entire project, use the Maven Surefire Plugin Ability to skip tests . There is a drawback to using skipTests from the command line. In a scenario for building multiple modules, this will disable all tests in all modules.
If you need finer grain control of running a subset of the tests for a module, consider using inclusion and exclusion for testing Maven Surefire Plugin .
To enable command line overrides, use the POM properties when configuring the Surefire plugin. Take, for example, the following POM segment:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.9</version> <configuration> <excludes> <exclude>${someModule.test.excludes}</exclude> </excludes> <includes> <include>${someModule.test.includes}</include> </includes> </configuration> </plugin> </plugins> </build> <properties> <someModule.skip.tests>false</someModule.skip.tests> <skipTests>${someModule.skip.tests}</skipTests> <someModule.test.includes>**/*Test.java</someModule.test.includes> <someModule.test.excludes>**/*Test.java.bogus</someModule.test.excludes> </properties>
With POM, as mentioned above, you can perform tests in various ways.
- Run all the tests (the above configuration includes all the source files ** / * Test.java).
mvn test
- Skip all tests in all modules
mvn -DskipTests=true test
- Skip all tests for a specific module
mvn -DsomeModule.skip.tests=true test
- Run only specific tests for a specific module (this example includes all ** / * IncludeTest.java source files).
mvn -DsomeModule.test.includes="**/*IncludeTest.java" test
- Exclude specific tests for a specific module (this example excludes all ** ** * * ExcludeTest.java source files)
mvn -DsomeModule.test.excludes="**/*ExcludeTest.java" test
Brent Worden Feb 04 2018-12-12T00: 00Z
source share