Maven – ユニットテストをスキップする方法
Mavenでは、 `-Dmaven.test.skip = true`というシステムプロパティを定義して、単体テスト全体をスキップすることができます。
デフォルトでは、プロジェクトをビルドするとき、Mavenはユニットテスト全体を自動的に実行します。ユニットテストが失敗した場合、Mavenはビルドプロセスを強制終了します。実際の生活では、いくつかのケースが失敗してもプロジェクトを構築する必要があります** 。
この記事では、ユニットテストをスキップする方法をいくつか紹介します。
1. maven.test.skip = true
1.1ユニットテストをスキップするには、この引数 `-Dmaven.test.skip = true`を使用します。
ターミナル
$ mvn package -Dmaven.test.skip=true #no test
1.2あるいは `pom.xml`で定義されています
pom.xml
<properties> <maven.test.skip>true</maven.test.skip> </properties>
ターミナル
$ mvn package #no test
2. Maven Surefire Plugin
2.1また、surefireプラグインでこの `-DskipTests`を使用してください。
ターミナル
$ mvn package -DskipTests #no test
2.2またはこれ。
pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M1</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin>
2.3いくつかのテストクラスをスキップする。
pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M1</version> <configuration> <excludes> <exclude>** ** /TestMagic** .java</exclude> <exclude>** ** /TestMessage** .java</exclude> </excludes> </configuration> </plugin>
3. Mavenプロファイル
3.1ユニットテストをスキップするカスタムプロファイルを作成します。
pom.xml
<profiles> <profile> <id>xtest</id> <properties> <maven.test.skip>true</maven.test.skip> </properties> </profile> </profiles>
3.2プロファイルを `-P`オプションでアクティブにします。
ターミナル
$ mvn package -Pxtest #no test
参考文献
シュアーファイアプラグイン]。
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
[結論
テストの除外]。
http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html
[Skipping
テスト]。
Mavenプロファイルの例
-
link://maven/how-to-run-unit-test-with-maven/[ユニットテストの実行方法
Mavenで]