1. 通过group关键字完成测试方法的分组,使用testng.xml中的<group>字段来指定分组;
class
package foo;
public class Calculate {
//加法
public int add(int num1,int num2) {
return num1+num2;
}
//减法
public int subtraction(int num1,int num2) {
return num1-num2;
}
//猫咪介绍
public void cat() {
System.out.println("我是一只猫咪");
}
//狗介绍
public void dog() {
System.out.println("我是一只小狗");
}
//绿箩介绍
public void scindapsus() {
System.out.println("我是一盆绿箩");
}
//君子兰介绍
public void clivia() {
System.out.println("我是一盆君子兰");
}
}
testng.xml
<test verbose="2" name="Test">
<groups>
<run>
<!-- <include name="非运算"></include> -->
<include name="动物"></include>
<include name="运算"></include>
</run>
</groups>
<classes>
<!-- <class name="foo.CalculateTest"/>
<parameter name="param1" value="1"/>
<parameter name="param2" value="2"/>
<class name="foo.AppTest"/> -->
<class name="foo.CalculateTest3"/>
testclass:
package foo;
import org.testng.annotations.Test;
public class CalculateTest3 {
@Test(groups= {"运算"})
public void addTest() {
System.out.println("加法测试");
}
@Test(groups= {"运算"})
public void subtractionTest() {
System.out.println("减法测试");
}
@Test(groups= {"动物","非运算"})
public void catTest() {
System.out.println("测试猫");
}
@Test(groups= {"动物","非运算"})
public void dogTest() {
System.out.println("测试狗");
}
@Test(groups= {"植物","非运算"})
public void scindapsusTest() {
System.out.println("测试绿箩");
}
@Test(groups= {"植物","非运算"})
public void cliviaTest() {
System.out.println("测试君子兰");
}
}