Maven不运行使用故障安全插件的集成测试
问题描述:
我知道这个问题被多次询问。但是我不能让Maven使用failsafe-plugin运行我的集成测试。Maven不运行使用故障安全插件的集成测试
当我执行mvn failsafe:integration-test failsafe:verify
它运行我的集成测试。 但是当我执行mvn verify
我的集成测试没有运行。
的pom.xml
<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.bahadirakin</groupId>
<artifactId>integration-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>integration-tests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
集成测试
package com.bahadirakin.integration;
import org.junit.Assert;
import org.junit.Test;
public class ServiceIT {
@Test
public void testFail() throws Exception {
Assert.fail();
}
}
正如你看到的我希望它失败。
Maven版本
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T23:58:10+03:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"
更新 mvn clean verify -X
输出link。
答
请改变你的构建节路(不含配置标签):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
+1
这样做是一个耻辱。非常感谢,在一百万年里,但我无法认识到这个错误。 – bhdrkn
答
我有这个配置我的故障保护IT测试:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
这确实无法运行的使用此命令的集成测试:
mvn test-compile failsafe:integration-test failsafe:verify
它只是报道没有测试运行! 所以我改变了插件,如下所示,它的工作:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
答
在我的基于Spring引导POM我不小心添加故障安全插件<pluginManagement>
部分,因此它没有添加到我的项目在所有。应该是:
<build>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
你可以尝试做'MVN清洁verify'和管道输出到一个文件和地方发布的文件.... – khmarbaise
“MVN清洁验证-X”可能是更有帮助 – cslysy
@ cslysy我将输出添加到[gist](https://gist.github.com/bhdrkn/7aea7046ff7c02947f36)。 – bhdrkn