!!!转载地址!!!
场景1:
public class TestngGroups { @Test(groups = { "group1", "group2" }) public void testMethod1() { System.out.println("testMethod1"); } @Test(groups = {"group1", "group2"} ) public void testMethod2() { System.out.println("testMethod2"); } @Test(groups = { "group1" }) public void testMethod3() { System.out.println("testMethod3"); } }
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <run> <inlude name="group2" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups" /> </classes> </test> </suite>
场景2:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <run> <include name="group1" /> <exclude name="group2" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups" /> </classes> </test> </suite>
场景3:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <define name="part"> <include name="group2" /> </define> <define name="all"> <include name="group1" /> <include name="group2" /> </define> <run> <include name="all" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups" /> </classes> </test> </suite>
场景4:
@Test(groups = { "class-group" }) public class TestngGroups2 { @Test(groups = { "method-group"}) public void method1() { System.out.println("Method1"); } public void method2() { System.out.println("Method2"); } } //method2()是组“class-group”的一部分,它在类级别定义,而method1()属于“class-group”和“method-group”两者。
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <run> <include name="method-group" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups2" /> </classes> </test> </suite>
场景5:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <run> <include name="class-group" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups2" /> </classes> </test> </suite>
场景6:
public class TestngGroups3 { @BeforeGroups(groups={"group-b"}) public void setUp(){ System.out.println("Method---setup"); } @AfterGroups(groups={"group-b"}) public void tearDown(){ System.out.println("Method---tearDown"); } @Test(groups = { "group-a" }) public void aaaMethod() { System.out.println("Method---aaa"); } @Test(groups = { "group-b"} ) public void bbbMethod() { System.out.println("Method---bbb"); } @Test(groups = { "group-a","group-b" }) public void cccMethod() { System.out.println("Method---ccc"); } }
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="login"> <groups> <run> <include name="group-b" /> </run> </groups> <classes> <class name="com.kdzwy.practice.TestngGroups3" /> </classes> </test> </suite>
标签:group,void,System,TestNG,分组,groups,public,out From: https://www.cnblogs.com/samsun1519/p/17839878.html