更新时间:2022-04-30 00:37:50
To toggle unit tests on and off for an entire project use Maven Surefire Plugin's capability of skipping tests. There is a drawback with using skipTests from the command line. In a multi-module build scenario, this would disable all tests across all modules.
If you need more fine grain control of running a subset of tests for a module, look into using the Maven Surefire Plugin's test inclusion and exclusion capabilities.
要允许命令行替代,请在配置Surefire插件时使用POM属性.以下面的POM段为例:
To allow for command-line overrides, make use of 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>
使用上述POM,您可以通过多种方式执行测试.
With a POM like the above you can execute tests in a variety of ways.
mvn test
mvn -DskipTests=true test
mvn -DsomeModule.skip.tests=true test
mvn -DsomeModule.test.includes="**/*IncludeTest.java" test
mvn -DsomeModule.test.excludes="**/*ExcludeTest.java" test