TestNG提供了很多执行方式,下面做简单介绍。
1.XML指明测试类,按照类名执行,其中可以指定包名,也可指定无包名:
带包名,运行ParameterSample类和ParameterTest类 <?xml version="1.0" encoding="UTF-8"?> <suite name="Suite1" verbose="1" > <test name="Regression1"> <classes> <class name="test.sample.ParameterSample"/> <class name="test.sample.ParameterTest"/> </classes> </test> </suite> 不带包名,不建议使用 <?xml version="1.0" encoding="UTF-8"?> <suite name="Suite1" verbose="1" > <test name="Nopackage" > <classes> <class name="NoPackageTest" /> </classes> </test> </suite>
2.XML指定包名,执行包内的所有测试类
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite1" verbose="1" > <test name="Regression1" > <packages> <package name="test.sample" /> </packages> </test> </suite>
3.XML指定组,需要在代码里面设定组
代码: @Test(groups={"g2"}) public void test4() { System.out.println("this is test4"); } @Test(groups={"g1"}) public void test5() { System.out.println("this is test5"); } @Test(groups={"g1"}) public void test10() { System.out.println("this is test10"); } XML: <?xml version="1.0" encoding="UTF-8"?> <suite name="Suite"> <test name="Test"> <groups> <run> <exclude name="g2" /> <include name="g1" /> </run> </groups> <classes> <class name="test.testng.TestOrder"/> </classes> </test> <!-- Test --> </suite> <!-- Suite -->