Maven –単体テストをスキップする方法
Mavenでは、システムプロパティ-Dmaven.test.skip=true
を定義して、単体テスト全体をスキップできます。
デフォルトでは、プロジェクトをビルドすると、Mavenはユニットテスト全体を自動的に実行します。 単体テストに失敗すると、Mavenはビルドプロセスを強制的に中止します。 実際には、一部のケースが失敗した場合でも、STILLでプロジェクトをビルドする必要がある場合があります。
この記事では、単体テストをスキップするいくつかの方法を紹介します。
1. maven.test.skip=true
1.1 To skip unit tests, uses this argument -Dmaven.test.skip=true
ターミナル
$ mvn package -Dmaven.test.skip=true #no test
1.2 Or defined in pom.xml
pom.xml
true
ターミナル
$ mvn package #no test
2. Maven Surefireプラグイン
2.1 Alternatively, use this -DskipTests
in surefire plugin.
ターミナル
$ mvn package -DskipTests #no test
2.2 Or this.
pom.xml
org.apache.maven.plugins maven-surefire-plugin 3.0.0-M1 true
2.3 To skip some test classes.
pom.xml
org.apache.maven.plugins maven-surefire-plugin 3.0.0-M1 **/TestMagic*.java **/TestMessage*.java
3. Mavenプロファイル
3.1 Create a custom profile to skip the unit test.
pom.xml
xtest true
3.2 Active the profile with a -P
option.
ターミナル
$ mvn package -Pxtest #no test