UT =单元测试IT =集成测试。我的所有集成测试类都用@Category(IntegrationTest.class)进行了注释
我的目标是:
mvn clean install =>运行UT而不是IT
mvn clean install -DskipTests=true =>不执行任何测试
mvn clean deploy =>运行UT而不是IT
mvn clean test =>运行UT而不是IT
mvn clean verify =>运行UT和IT
mvn clean integration-test =>运行IT,不执行UT
mvn clean install deploy =>运行UT而不是IT
pom属性:
<junit.version>4.12</junit.version>
<surefire-plugin.version>2.18.1</surefire-plugin.version>
<failsafe-plugin.version>2.18.1</failsafe-plugin.version>org.apache.maven.plugins maven-compiler-plugin 2.5.1 1.8 1.8 -Xlint:all true true
org.apache.maven.plugins maven-surefire-plugin ${surefire-plugin.version} com.xpto.IntegrationTest
org.apache.maven.plugins maven-failsafe-plugin ${failsafe-plugin.version} com.xpto.IntegrationTest集成测试**/*.class
我的结果是:
mvn clean install =>正常
mvn clean install -DskipTests=true =>正常
mvn clean deploy =>运行UT而不是IT
mvn clean test =>正常
mvn clean verify => NOK...只执行UT,但也需要执行IT
mvn clean integration-test => NOK...UT已执行但不应执行,IT未执行但应执行
mvn clean install deploy =>正常
发布于 2015-10-24 03:53:19
解决方案是:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>${surefire.skip}</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>这将让您控制执行的是哪一个。
运行UT和IT:
mvn clean verify运行IT而不是UT
mvn clean verify -Dsurefire.skip=true 运行UT,但不运行IT:
mvn clean verify -DskipITs=true 您需要遵循插件的命名约定,这将使您的工作更轻松。
maven-surefire- Naming conventions插件(单元测试)。maven-failsafe- Naming conventions插件(集成测试)。
https://stackoverflow.com/questions/33308037
复制相似问题