2010-01-28 40 views
2

我正在運行Maven的Junit測試。 Ant腳本有當JUnit失敗時,如何停止Maven?

<junit failureproperty="failproperty" errorproperty="errorproperty">   
        <classpath refid="classpath" /> 
        <test name="${unit-test-suite}" /> 
        <formatter type="brief" usefile="false" /> 
     </junit> 

     <echo> ----------> ${failproperty} </echo> 
     <echo> ----------> ${errorproperty} </echo> 
     <fail message="something wrong" if="${failureproperty}"/> 
     <fail message="something wrong" if="${errorproperty}"/> 

我試圖

  • 停止在錯誤或失敗的Junit - 這個暫停的時候我只運行ant腳本,但建立在Maven的成功並沒有停止,甚至想過的JUnit有錯誤。

    • 我試圖通過設置errorproperty和failure屬性來發送失敗消息 - 這不會設置變量。

我如何告訴Maven的Junit的時候都無法阻止一切嗎?

Maven的詳細信息:

Maven version: 2.0.10 
Java version: 1.6.0_17 
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows" 

回答

1

這種 「快速失敗」 功能目前尚未通過的Maven 2的支持,看到SUREFIRE-580(也許爲它投票)。

0

你確定你正確設置屬性?

請注意,if和unless屬性帶有屬性名稱,而不是表達式。例如,嘗試使用:的

<fail if="failproperty"/>代替<fail if="${failproperty}"/>

<fail/>標籤在這個簡單的例子工程。嘗試mvn package然後mvn package -Dfailproperty=true

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>ant-test</groupId> 
    <artifactId>ant-test</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.7</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>ant-test</id> 
         <phase>package</phase> 
         <configuration> 
          <tasks> 
           <junit failureproperty="fail"> 
            <classpath> 
             <path refid="maven.plugin.classpath"/> 
             <path refid="maven.test.classpath"/> 
            </classpath> 
            <formatter type="plain" /> 
            <batchtest> 
             <fileset dir="src/test/java"/> 
            </batchtest> 
           </junit> 
           <fail if="fail"/> 
          </tasks> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.ant</groupId> 
         <artifactId>ant-junit</artifactId> 
         <version>1.7.1</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <skipTests>true</skipTests> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

src/test/java假設一個測試用例:

import junit.framework.Assert; 

import org.junit.Test; 

public class FakeTestCase { 

    @Test 
    public void testThis() { 
     Assert.fail("Failure"); 
    } 

} 
+0

如果我通過在參數,像你這樣做則是它的工作原理,但失敗財產不被設置,如果我從運行maven甚至當我得到一個JUnit錯誤。在您的項目中嘗試 – unj2 2010-01-28 21:11:39

+0

它的工作原理。查看更新的項目 – Kevin 2010-01-28 21:20:42

相關問題