執(zhí)行結(jié)果:
groups = { functest }
PASSED: testMethod3
===============================================
TestGroups
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
framework_testng
Total tests run: 1, Failures: 0, Skips: 0
===============================================
當(dāng)我們的測(cè)試用例累積了很多以后,我們可能不需要測(cè)試之前的分組,只要測(cè)試剛剛寫(xiě)好的分組,這時(shí)候testng提供了一種新的配置方式,來(lái)實(shí)現(xiàn)這一功能,讓測(cè)試人員只修改配置文件完成測(cè)試
注意:多個(gè)group測(cè)試時(shí),xml文件dom順序必須是'<groups>'標(biāo)簽必須在'<test>'標(biāo)簽內(nèi), 否則會(huì) 有空指針異常
/**
*
* <p>
* Title: TestngGroupsOfGroups
* </p>
*
* <p>
* 參考配置文件:testng-groupsOfGroups.xml
* Description:使用<define>標(biāo)簽將測(cè)試方法在組內(nèi)再次進(jìn)行分組并以name屬性進(jìn)行區(qū)分,
* <run>通過(guò)define標(biāo)簽的name進(jìn)行調(diào)用,以后修改測(cè)試直接修改run調(diào)用的名稱即可
*
* 注:<b>多個(gè)group測(cè)試時(shí),xml文件dom順序必須是'<groups>'標(biāo)簽必須在'<test>'標(biāo)簽內(nèi), 否則會(huì) 有空指針異常
* </p>
*
* <p>
* Company:
* </p>
*
* @author : Dragon
*
* @date : 2014年10月13日
*/
public class TestngGroupsOfGroups {
@Test(groups = { "windows.xp" })
public void testMethod5() {
System.err.println("(groups = { windows.xp })");
}
@Test(groups = { "windows.7" })
public void testMethod6() {
System.err.println("(groups = { windows.7 })");
}
@Test(groups = { "windows.8" })
public void testMethod7() {
System.err.println("(groups = { windows.8 })");
}
}
配置文件:testng-groupOfGroups.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd">
<suite name="framework_testng">
<test verbose="2" name="TestGroupsOfGroups">
<groups>
<define name="windows.xp">
<include name="windows.xp" />
</define>
<define name="windows.7">
<include name="windows.7" />
</define>
<define name="all">
<include name="windows.*" />
</define>
<run>
<include name="all" />
<exclude name="windows.7" />
</run>
</groups>
<classes>
<class name="com.dragon.testng.annotation.TestngGroupsOfGroups" />
</classes>
</test>
</suite>
測(cè)試結(jié)果:(注意:此時(shí) 被運(yùn)行的測(cè)試分組將在run標(biāo)簽內(nèi)進(jìn)行配置,include和exclude時(shí),是根據(jù)Define標(biāo)簽的name來(lái)決定)
(groups = { windows.xp })
(groups = { windows.8 })
PASSED: testMethod5
PASSED: testMethod7
===============================================
TestGroupsOfGroups
Tests run: 2, Failures: 0, Skips: 0
===============================================