![](/img/trans.png)
[英]Running Multiple testng suites in parallel with different parameters for each of those suites
[英]Running different test suites using testng and maven
我正在使用TestNg和Maven以及surefire插件來運行我的測試。 我有幾個不同的組件,我希望能夠使用相同的pom在不同的時間運行。 目前為了做到這一點,我有幾個不同的XML文件定義測試套件,我有pom設置,所以我可以做mvn test -Dtestfile = / path並使用該套件。
我想知道是否有辦法將XML文件合並到一個文件中並選擇基於測試名或其他系統?
編輯:我已經使用Smoke,Sanity,Regression定義了所有測試,並且我希望能夠為給定組件運行所有回歸。 如果我運行TestNG CLI,我可以給出-testnames comp1,comp2,comp3等。 其中每個組件在一個包含多個tests()的xml套件中定義。 我想知道是否有任何方法可以在maven中使用exec:java插件。
TestNG支持測試組,可以通過在測試用例本身中的測試類/方法上指定組,也可以在suite.xml文件中指定組。 通過使用組,您可以將所有測試放在一個xml文件中。 見組 TestNG的用戶指南中。
surefire插件允許根據組包含或排除測試:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<groups>${testng.groups}</groups>
</configuration>
</plugin>
您可以將所有測試放在一個xml文件中,然后通過將一個或多個組設置為包含在$ {testng.groups}屬性中來選擇要運行的測試,該屬性應該是以逗號分隔的組名列表。
您可以使用配置文件或命令行-Dtestng.groups=[groups to run]
在POM中定義$ {testng.groups}屬性的值。
您可以做的是定義不同的配置文件
<profiles>
<profile>
<id>t1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
並通過mvn -Pt1從命令行調用...或在配置文件中定義屬性並在配置中使用該屬性。
另請注意,TestNG允許您將多個套件合並為一個,例如,如果您想將api和ui冒煙測試合並到一個套件中:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="uber-smoke-suite" verbose="1" parallel="methods" thread-count="1" configfailurepolicy="continue">
<suite-files>
<suite-file path="smoke_api.xml" />
<suite-file path="smoke_ui.xml" />
</suite-files>
</suite>
這樣你也可以創建一個超級套件,將所有測試合並為一個,但仍允許你在必要時運行單個套件,例如:
-Dtestfile=smoke
-Dtestfile=smoke_api
-Dtestfile=smoke_ui
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.