目前,我的集成测试仅在运行mvn install
时运行。我希望在mvn test
时运行它们。
我的<pluginManagement>
部分包含:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
</pluginManagement>
如果我只提供目标test
?
答案 0 :(得分:1)
实际上有特殊的阶段 用于运行集成测试:
他们按顺序运行,所以如果你打电话
mvn integration-test
并且失败,将不会调用集成后测试阶段。
但是如果你想在“测试”阶段调用它,只需将测试移到适当的阶段:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
答案 1 :(得分:-1)
与单元测试不同,默认情况下不执行集成测试。 您必须在pom.xml中使用与集成测试相关的配置创建单独的配置文件,并在指定目标时使用此配置文件。 例如:
<profiles>
<profile>
<id>integration-test</id> // name of the profile
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration/java</source> // location where your code related to integration tests are present
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration/resources</directory> // location where resources related to your integration tests are present
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<failIfNoTests>false</failIfNoTests>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
现在,为了运行集成测试,您可以按如下方式发出maven命令:
mvn clean install -P integration-test
这里-P选项用于指定配置文件,integration-test是我们之前在pom.xml中创建的配置文件名称