2013-05-27 92 views
0

我正在嘗試使用@Category - JUnit和配置文件的註釋來分解集成測試和冒煙測試。因此,如果我運行mvn clean install -P smoke-tests,則只有Smoke-Tests得到執行,並且如果我運行mvn clean install,則每個測試都會運行。爲什麼<excludeGroups>工作但<groups>不?

的事情是:

當我排除的羣體中的Maven與<excludeGroups>它不包括組預期。但是,當我嘗試將它們包含在<groups>中時,它仍然會運行每個測試。 Maven的代碼是沒有任何幻想:

<profile> 
    <id>smoke-tests</id> 
    <activation> 
     <activeByDefault>false</activeByDefault> 
    </activation> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <version>2.12</version> 
       <configuration> 
        <parallel>classes</parallel> 
        <threadCount>4</threadCount> 
        <perCoreThreadCount>false</perCoreThreadCount> 
        <!-- <excludeGroups>de.package.SmokeTest</excludeGroups> --> 
        <groups>de.package.SmokeTest</groups> 
       </configuration> 
       <executions> 
        <execution> 
         <goals> 
          <goal>integration-test</goal> 
          <goal>verify</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</profile> 

我當然可以通過使用<include><exclude>解決這個問題,但我真的想使用@Category註解。

任何幫助表示讚賞。

回答

1

這是一個在2.12.1:JUnit categories only work when junit47 provider is explicitly set中修復的錯誤。如果你不能升級,明確指定一個junit提供者,它應該工作:

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    <configuration> 
    <groups>uk.co.farwell.test.SlowTests</groups> 
    </configuration> 
    <dependencies> 
    <dependency> 
     <groupId>org.apache.maven.surefire</groupId> 
     <artifactId>surefire-junit47</artifactId> 
     <version>2.12</version> 
    </dependency> 
    </dependencies> 
</plugin> 
+0

謝謝你的回答。我用'mvn test'試過了你的解決方案,Maven沒有運行任何測試。它只顯示'測試運行:0,失敗:0,錯誤:0,跳過:0' – tk2000

+1

您試過了哪種解決方案?升級到2.12.1或添加依賴項? –

+0

其實都是:( – tk2000

相關問題