TestNG Tutorial 5 – Suite Test
Written on
May 14, 2009 at 2:04 pm by
mkyong
The “Suite Test” means bundle a few unit test and run it together.
XML file is use to run the suite test. The below XML file means both unit test “TestNGTest1” and “TestNGTest2” will run it together
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > <suite name="My test suite"> <test name="testing"> <classes> <class name="TestNGTest1" /> <class name="TestNGTest2" /> </classes> </test> </suite>
TestNG can do more than bundle class testing, it can bundle method testing as well. With TestNG unique “Grouping” concept, every method is tie to a group, it can categorize tests according to features. For example,
Here is a class with four methods, three groups (method1, method2 and method3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import org.testng.annotations.*; /** * TestNG Grouping * @author mkyong * */ public class TestNGTest5_2_0 { @Test(groups="method1") public void testingMethod1() { System.out.println("Method - testingMethod1()"); } @Test(groups="method2") public void testingMethod2() { System.out.println("Method - testingMethod2()"); } @Test(groups="method1") public void testingMethod1_1() { System.out.println("Method - testingMethod1_1()"); } @Test(groups="method4") public void testingMethod4() { System.out.println("Method - testingMethod4()"); } } |
With the following XML file, we can execute the unit test with group “method1” only.
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > <suite name="My test suite"> <test name="testing"> <groups> <run> <include name="method1"/> </run> </groups> <classes> <class name="TestNGTest5_2_0" /> </classes> </test> </suite>
Result
Method – testingMethod1_1()
Method – testingMethod1()


