【问题标题】:Maven does not run integration tests using failsafe-pluginMaven 不使用故障安全插件运行集成测试
【发布时间】:2015-05-14 08:38:50
【问题描述】:

我知道这个问题被问了不止一次。但是我不能让 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

【问题讨论】:

  • 你能不能尝试做mvn clean verify 并将输出传送到一个文件中并将文件发布到某个地方......
  • "mvn clean verify -X" 可能会更有帮助
  • @cslysy 我将输出添加到gist

标签: java maven maven-failsafe-plugin integration-testing


【解决方案1】:

请以这种方式更改您的构建部分(不带 configuration 标签):

<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>

【讨论】:

  • 犯这样的错误很可惜。非常感谢,在一百万年后,但我无法识别这个错误。
【解决方案2】:

在我基于 Spring Boot 的 POM 中,我不小心将故障安全插件添加到 &lt;pluginManagement&gt; 部分,因此它根本没有添加到我的项目中。应该是:

<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>

【讨论】:

  • 感谢您发布此内容,为我节省了很多时间。
【解决方案3】:

我的故障安全 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>
         

【讨论】:

    猜你喜欢
    • 2013-11-12
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    相关资源
    最近更新 更多