2010-01-28 3 views
2

Maven에서 Junit 테스트를 실행하고 있습니다. 개미 스크립트는 내가 JUnit을에 오류 또는 실패에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을을도 생각 중지하지 않는 경우 오류가 있습니다.

    • errorproperty 및 failure 속성을 설정하여 실패 메시지를 보내려고했습니다. 이것은 변수를 설정하지 않습니다.

어떻게를 JUnit 실패하면 모든 것을 중지 메이븐을 알 수 있습니까?

메이븐 상세 사항 :

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

답변

1

이 기능을 "빨리 실패하는 것은"현재 메이븐 2를 지원하지 않습니다, SUREFIRE-580를 참조 (그리고 아마 투표).

0

속성을 올바르게 설정 하시겠습니까?

if 및 unless 속성은 표현식이 아닌 속성 이름을 사용합니다. 예를 들어, 사용 시도해보십시오 <fail/> 태그는이 간단한 예제에서 작동

<fail if="failproperty"/> 대신

<fail if="${failproperty}"/>의. 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

당신처럼 내가 인수를 전달하는 경우 다음 예는 내가에서 실행하면 속성이 설정되지 않습니다 실패를 제외한 작동 심지어 JUnit 오류가 발생하면 maven. 귀하의 프로젝트에서 그것을 시도하십시오 – unj2

+0

그것은 작동합니다. 업데이트 된 프로젝트보기 – Kevin

관련 문제