2012-04-30 62 views
6

是否可以通過maven從命令行運行預定義的xml套件?TestNG surefire,使用maven命令行運行套件

我能夠運行一個類或特定的測試。但我無法運行套件。

這裏就是我在命令行中運行: - >

mvn -Dtest=TestCircle#mytest -Denvironment=test -Dbrowser=firefox -DscreenShotDirectory=/Users/jeremy/temp test 

我有定義的套件,它通過很好的IntelliJ運行,但我不知道如何調用該套件。 xml文件。

或者例如,在測試運行後,testng會創建一個testng失敗的文件,該文件被設置爲再次運行所有失敗的測試。

使用mvn,我將如何開始測試套件。

+0

我在這裏找到了答案:http://stackoverflow.com/questions/11762801/run-junit-suite-using-maven-command – Philippe

回答

5

通常你不需要任何特別的與TestNG的關係。只需使用maven-surefire插件:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    </plugin> 

並基於所有正確註釋的測試應運行。啊,當然你需要這樣的依賴關係TestNG的:

<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.5.2</version> 
    <scope>test</scope> 
</dependency> 

通常我不會創建測試套件了,導致這個,你必須保持它常常被漏診更新等只使用註釋的點。

如果您需要運行一個特定的測試套件,只需在src/test/resources中定義一個testng.xml文件,並適當增強maven-surefire plugin的配置。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    <configuration> 
     <suiteXmlFiles> 
     <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
     </suiteXmlFiles> 
    </configuration> 
    </plugin> 
4
<build> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.12</version> 
    <configuration> 
     <suiteXmlFiles> 
     <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
     </suiteXmlFiles> 
    </configuration> 
    </plugin> 
</build> 

它爲我工作。

+0

我做了同樣的方式,但不幸的是它沒有工作 –

14

這個答案給了我什麼,我一直在尋找,即在命令行傳遞我要運行的套件名稱的能力:

http://www.vazzolla.com/2013/03/how-to-select-which-testng-suites-to-run-in-maven-surefire-plugin/

簡而言之,添加以下你的pom.xml的Maven的surfire-插件節:

<suiteXmlFiles> 
    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> 
</suiteXmlFiles> 

然後你可以指定在命令行中所需的TestNG的套件XML文件:

mvn clean install test -DsuiteXmlFile=testngSuite.xml 
相關問題