2015-05-14 70 views
5

我知道這個問題被多次詢問。但是我不能讓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

+0

你可以嘗試做'MVN清潔verify'和管道輸出到一個文件和地方發佈的文件.... – khmarbaise

+0

「MVN清潔驗證-X」可能是更有幫助 – cslysy

+0

@ cslysy我將輸出添加到[gist](https://gist.github.com/bhdrkn/7aea7046ff7c02947f36)。 – bhdrkn

回答

16

請改變你的構建節路(不含配置標籤):

<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

0

我有這個配置我的故障保護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> 
0

在我的基於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> 
相關問題