2011-08-22 3 views
3

Maven으로 프로젝트를 빌드 할 때마다 실행하고 싶지 않은 데이터베이스에 의존하는 느린 테스트가 있습니다. 내 pom 파일에 http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups 설명한 excludedGroups 요소를 추가 한 있지만 작동시키지 수 없습니다.Maven에서 TestNG 그룹 제외

최소한의 프로젝트를 만들었습니다. 여기에 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>test</groupId> 
    <artifactId>exclude</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <build> 
     <plugins> 
      <plugin> 
       <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> 
       <version>2.4.2</version> 
       <configuration> 
        <excludedGroups>db</excludedGroups> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>5.14</version> 
     </dependency> 
    </dependencies> 

</project> 

그리고이 두 테스트 클래스이다 : 그러나 테스트 모두가 여전히 실행

public class NormalTest { 

    @Test 
    public void fastTest() { 
     Assert.assertTrue(true); 
    } 
} 

public class DatabaseTest { 

    @Test(groups={"db"}) 
    public void slowTest() { 
     Assert.assertTrue(false); 
    } 
} 

합니다. 나는 내가 뭘 잘못하고 있는지 알 수 없다.

답변

5

나는 외부 테스트 슈트를 만들어 결국 ...

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.11</version> 
    <configuration> 
     <suiteXmlFiles> 
      <suiteXmlFile>src/test/resources/suites/standard.xml</suiteXmlFile> 
     </suiteXmlFiles> 
    </configuration> 
</plugin> 

<profile> 
    <id>fulltest</id> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <suiteXmlFiles> 
         <suiteXmlFile>src/test/resources/suites/full.xml</suiteXmlFile> 
        </suiteXmlFiles> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</profile> 
3

내 경험에 의하면, 제외 된 그룹 기능은 포함 된 그룹 집합이있는 경우에만 작동합니다. 따라서 원하는 것을하기 위해서는 적어도 하나의 그룹에 모든 테스트를 추가해야합니다 (메소드보다는 클래스에 주석을 달아 "쉽게"할 수 있습니다).

예를 들어

@Test(groups = "fast") 
public class NormalTest { 

    @Test 
    public void slowTest() { 
     Assert.assertTrue(true); 
    } 
} 

를 (단지 NormalTest 변경) 및 구성

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.4.2</version> 
      <configuration> 
       <groups>fast</groups> 
       <excludedGroups>db</excludedGroups> 
      </configuration> 
     </plugin> 

에서 나는이 분명 아니라는 것을 알고 있지만, TestNG를 작동하는 방법 : S를. 부수적으로 필자는 항상 pmm의 임베디드 구성을 테스트하는 데 외부 구성 파일을 사용 했으므로 groups 매개 변수가 올바르지 않을 수 있습니다.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > 
<suite name="tests"> 
     <test name="standard"> 
     <groups> 
      <run> 
       <exclude name="slow" /> 
       <exclude name="external" /> 
       <exclude name="db" /> 
      </run> 
     </groups> 
     <packages> 
      <package name="com.test.*" /> 
     </packages> 
    </test> 
</suite> 

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > 
<suite name="tests"> 
    <test name="full"> 
     <packages> 
      <package name="com.test.*" /> 
     </packages> 
    </test> 
</suite> 

및 specifyied 프로파일에서 실행 :

+2

이것은 Maven (실제로 Surefire)의 제한 사항으로 TestNG가 아닌 것으로 보입니다. TestNG 만 사용하면 그룹을 제외하지 않고도 그룹을 제외 할 수 있습니다. –

+0

모든 테스트에 그룹을 추가하고 pom에서 그룹을 지정하려고 시도했지만 아무런 차이가없는 것 같습니다. – samblake

+1

감사합니다. 이것은 저에게 도움이되었습니다. "그룹"과 "제외 된 그룹"은 예상대로 작동 했으므로 함께 사용하거나 단독으로 사용할 수 있습니다. 테스트 대상 : Maven 2.2.1, maven-surefire-plugin 2.4.3, testng 5.14.6. – pestrella