TestNG MetaGroups - 組的組
TestNG 允許定義可包含其他組的組。MetaGroups 邏輯上組合一個或多個組,並控制屬於這些組的 @Test
方法的執行。
在以下示例中,存在屬於不同組的各種 @Test
方法。很少有特定的堆疊,很少是迴歸和驗收測試。這裡可以建立 MetaGroups。讓我們選擇任意兩個簡單的 MetaGroup :
allstack
- 包括liux.jboss.oracle
和aix.was.db2
組,並使屬於這些組中的任何一個的所有測試方法一起執行。systemtest
- 包括allstack
,regression
和acceptance
組,並使屬於這些組中的任何一個的所有測試方法一起執行。
testng.xml 配置
<suite name="Groups of Groups">
<test name="MetaGroups Test">
<groups>
<!-- allstack group includes both liux.jboss.oracle and aix.was.db2 groups -->
<define name="allstack">
<include name="liux.jboss.oracle" />
<include name="aix.was.db2" />
</define>
<!-- systemtest group includes all groups allstack, regression and acceptance -->
<define name="systemtest">
<include name="allstack" />
<include name="regression" />
<include name="acceptance" />
</define>
<run>
<include name="systemtest" />
</run>
</groups>
<classes>
<class name="example.group.MetaGroupsTest" />
</classes>
</test>
</suite>
MetaGroupsTest 類
package example.group;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MetaGroupsTest {
@BeforeMethod
public void beforeMethod(){
//before method stuffs - setup
}
@Test(groups = { "liux.jboss.oracle", "acceptance" })
public void testOnLinuxJbossOracleStack() {
//your test logic goes here
}
@Test(groups = {"aix.was.db2", "regression"} )
public void testOnAixWasDb2Stack() {
//your test logic goes here
}
@Test(groups = "acceptance")
public void testAcceptance() {
//your test logic goes here
}
@Test(groups = "regression")
public void testRegression(){
//your test logic goes here
}
@AfterMethod
public void afterMthod(){
//after method stuffs - cleanup
}
}