2013-10-29 96 views
0

爲什麼使用TestNG時'mvn test'爲我工作,但不是'mvn surefire:test'?它很有趣,因爲套件xml文件的位置是通過surefire插件配置的,但只有在執行常規Maven「測試」目標時纔會運行。當我使用'mvn surefire:test'時,那麼當文件物理上似乎存在於預期的位置時,就好像資源(或src/test/resources/testng.xml)文件對測試執行程序不可見:/ target /test-classes/testng.xml。爲什麼'mvn test'在使用TestNG時爲我工作,而不是'mvn surefire:test'?

這是我的配置。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${maven-surefire.version}</version> 
    <configuration> 
     <includes> 
     <include>Tests/**/*.java</include> 
     </includes> 
     <suiteXmlFiles> 
      <suiteXmlFile> 
       ${project.build.testOutputDirectory}/${testng.suitexmlfile} 
        </suiteXmlFile> 
     </suiteXmlFiles> 
     <configuration> 
      <systemPropertyVariables> 
       <build-name>${testng.buildname}</build-name> 
       <testenv>${testng.testenv}</testenv> 
      </systemPropertyVariables> 
      <groups>${testng.groups}</groups> 
     </configuration> 
    </configuration> 
</plugin> 

回答

0

MVN神火:測試將找不到任何測試,如果資源沒有被編譯之前執行。

因此這將不會找到任何測試執行:

mvn clean 
mvn surefire:test 

然而,這應該工作(因爲MVN清潔勢必Maven的生命週期和執行測試之前,編譯源):

mvn clean 
mvn test 
相關問題