TestNG提供了很多執(zhí)行方式,下面做簡(jiǎn)單介紹。
1.XML指明測(cè)試類,按照類名執(zhí)行,其中可以指定包名,也可指定無包名:
帶包名,運(yùn)行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指定包名,執(zhí)行包內(nèi)的所有測(cè)試類
<?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指定組,需要在代碼里面設(shè)定組
代碼: @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 -->