我同时在同一个包中编写了单元测试和集成测试。问题是我的单元测试是使用mvn test执行的,但是当我使用mvn verify时,我的集成测试没有执行。它只是执行单元测试。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.study</groupId>
<artifactId>integration-tests-rnd</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>integration-tests-rnd</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>MyIT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
import junit.framework.*;
public class MyIT extends TestCase {
public MyIT(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(MyIT.class);
}
public void testApp() {
System.out.println("Integration tests now getting executed because of maven plugin....");
assertTrue(true);
}
}
答案 0 :(得分:1)
由于您使用的是<pluginManagement/>
而不是<plugins/>
,因此您的代码会声明failafe插件的默认值。声明默认值,但不主动描述 IT NEEDS IT 。
删除外部<pluginManagement/>
部分,然后进行设置。我的意思是,这个:
<build>
<plugins>
<plugin>
<!-- your plugin description -->
</plugin>
</plugins>
</build>