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
}
}