2013-07-23 3 views
5

잠시 동안 한 빌드에서 jUnit 테스트 및 testNG 테스트를 실행하도록 maven surefire를 구성 할 수 있습니다. 나는 왜 그렇게하는지에 대한 이유를 확장하지 않을 것이다. (ok, 힌트 : testNG는 표준 프레임 워크이지만 jnario과 같은 일부 프레임 워크는 jUnit이 필요하다.)어떻게하면 JUnit과 TestNG 테스트를 제대로 실행할 수 있습니까?

을 수행하는 일반적인 방법은이 같은 확실한 플러그인을 구성하는 것입니다 : 이것은 아주 잘 작동

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${surefire.version}</version> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.maven.surefire</groupId> 
      <artifactId>surefire-junit47</artifactId> 
      <version>${surefire.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.maven.surefire</groupId> 
      <artifactId>surefire-testng</artifactId> 
      <version>${surefire.version}</version> 
     </dependency> 
    </dependencies> 
</plugin> 

(taken from here)

, JUnit 테스트 및 TestNG를 테스트 실행하세요.

하지만 testNG는 jUnit 테스트를 실행하려고 시도합니다. (물론 그 반대도 마찬가지입니다.) 물론 아무런 주석도 표시되지 않기 때문에 성공하지 못했지만 - "통과 한"테스트 ... 어쨌든, 일부보고 도구는 두 번째 종속 항목을 주석 처리하지 않으면 jUnit 테스트에서 테스트가 더 이상 실패하지 않음을 보여줍니다.

두 프레임 워크의 테스트가 테스트 주자에 의해서만 실행되도록 확실하게 구성하는 더 좋은 방법이 있습니까?

+0

Maven-Users-List에 크로스 게시 : http : //maven.40175.n5.nabble.com/maven-surefire-selecting-providers-td5764817.html –

답변

1

필자는 직접 해보지 않았지만, Maven-surefire-plugin을 두 개 구성하고 이러한 실행 중 하나가 JUnit 테스트 만 실행하고 다른 테스트 만이 testNG 테스트 만 실행하도록 구성 할 수 있습니다. JUnit과 testNG 테스트를 구분하려면 테스트를 다른 디렉토리에 두거나 구분 가능한 이름 체계를 사용하고 각 실행을 적합한 inclusion and exclusion patterns으로 구성해야합니다.

이론적으로이

+0

실행에''요소를 가져올 수 없습니다. 만약 내가 할 수 있다면, 실제로 * 솔루션, 하나의 실행은 jUnit으로 제한되고, 다른 하나는 TestNG로 이루어질 것입니다. ( –

+0

당신은 저를 잘못 생각했습니다. 원래의 질문과 같이 두 가지 를 가져야했습니다. 하나의 실행은 JUnit 테스트 만 찾고 다른 테스트 엔진은 testNG 테스트 만 찾을 수 있습니다. 이렇게하면 원치 않는 테스트가 확실하게 필터링되어 테스트 프레임 워크로 전달되지 않습니다. –

+1

아, 예, 나는 그것도 시도했다. (그리고 더 나 빠졌다) TestNG는 모든 실행에 대해 활성화된다. 실행을위한 테스트가 하나도 없다면 빌드가 실패한다. (예, 속성이있다.) - 누군가 버그를 발견 한 것처럼 보인다. 메이븐 사용자 메일 링리스트에서 [문제점보고] (https://jira.codehaus.org/browse/SUREFIRE-1019). +1 답변 및 도움에 +1 –

4

: 당신과 같은 문제를 겪고 작동합니다. TestNG 보고서에서는 0이 나오지만 테스트가 실행 된 것처럼 보입니다. 마지막 먼저 플러그인에서 dependencies 섹션을 제거 maven-surefire-plugin

  1. 의 두 개의 별도의 실행에이 일을 얻을.
    • 그렇지 않으면 <testNGArtifactName>를 사용 (우리는 그것을해야합니다) 시험은 어쨌든 TestNG를에 의해 실행되고 java.lang.NullPointerException
  2. 가 TestNG의 테스트와 JUnit 테스트의 일부 분리를 가지고에 실패합니다.
<plugin> 
    <!-- configured to work with JUnit and TestNg in same project separatelly --> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId>    
    <configuration> 
     <!-- whatever you need... --> 
     <!-- skip the default execution, we have separate for Ng and for JUnit --> 
     <skip>true</skip> 
    </configuration> 
    <executions> 
     <execution> 
      <id>TestNg-execution</id> 
      <phase>test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      <configuration> 
       <!-- overwrite skip from default config --> 
       <skip>false</skip> 
       <includes> 
        <include>%regex[.*TestNg.*]</include> 
       </includes> 
       <!-- used to skip JUnit profider --> 
       <junitArtifactName>dev:null</junitArtifactName> 
       <!-- to continue on next execution in case of failures here --> 
       <testFailureIgnore>true</testFailureIgnore> 
      </configuration> 
     </execution> 
     <execution> 
      <id>JUnit-execution</id> 
      <phase>test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      <configuration> 

       <skip>false</skip> 
       <!-- used to skip TestNg profider --> 
       <testNGArtifactName>dev:null</testNGArtifactName> 
       <excludes> 
        <exclude>%regex[.*TestNg.*]</exclude>        
       </excludes> 
      </configuration>      
     </execution> 
    </executions> 
</plugin> 

과 함께 테스트 : 우리의 경우 NG 테스트 클래스 이름에서 두 <executions> 아래와 같이 정의 TestNg

  • 스킵 기본 실행
  • 로 끝나는

    <junit-version>4.11</junit-version> 
    <maven-surefire-plugin-version>2.16</maven-surefire-plugin-version> 
    <org.testng-version>6.8.7</org.testng-version> 
    

    이 구성은의 마지입니다 아이디어 :
    Running TestNG-, JUnit3- and JUnit4-tests with Maven Surefire in one run,
    your SUREFIRE bug report,
    surefire plugin configuration

    희망이 있습니다.

  • +0

    Excelent solution! – bedrin

    관련 문제