发现testng比junit更牛逼的,特此保留官网链接,留着备用
http://testng.org/doc/documentation-main.html#testng-xml
付上自己写的简单例子:(在eclipse 中下载testng插件,加载testng jar包)
1 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > 2 3 <suite name="Suite1" verbose="1"> 4 <test name="Nopackage"> 5 <classes> 6 <class name="FirstTestNG" /> 7 <class name="SecondTestNG" /> 8 </classes> 9 </test> 10 11 <test name="Regression1" preserve-order="false"> 12 <classes> 13 <class name="com.testng.FirstTestNG" > 14 15 <methods> 16 <include name="checkEmpty"> 17 <parameter name="s" value="a"></parameter> 18 <parameter name="t" value="b"></parameter> 19 </include> 20 21 <include name="checkEmpty1"></include> 22 23 24 </methods> 25 </class> 26 <class name="com.testng.SecondTestNG" /> 27 </classes> 28 29 <!-- <packages> <package name="com.testng"></package> </packages> --> 30 </test> 31 32 <groups> 33 <run> 34 <exclude name="brokenTests"></exclude> 35 <include name="checkinTests"></include> 36 37 </run> 38 39 </groups> 40 41 </suite>
package com.testng; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class FirstTestNG { @Parameters({"s","t"}) @Test(groups ="checkinTests") public void checkEmpty(String s,String t) { System.out.println("---"+s+t); assert "ab".equals(s+t); } @Test(groups ="checkinTests") public void checkEmpty1() { assert "b".equals("b"); } }