TestNG入门指导——include/exclude中的正则表达式

TestNG中的include/exclude属性支持使用正则表达式,下面让我们一起来学习其用法:新建一个java项目,如下结构


RegularExpClass中增加如下代码:

package test.regularexppackage;
import org.testng.annotations.Test;


public class RegularExpClass {

@Test
public void includeTestFirst(){
System.out.print("First include test method");
}

@Test
public void includeTestSecond(){

System.out.print("Second include test method");
}

@Test
public void excludeTestFirst(){

System.out.println("First exclude test method");
}

@Test
public void excludeTestSecond(){

System.out.println("Second exclude test method");

}


@Test
public void includeMethod(){

System.out.println("Include method");

}

@Test
public void excludeMethod(){

System.out.println("Exclude method");
}
}


excreg-testng.xml中增加如下配置信息 (testNG 中任意字符的表示方法 .*)

<?xml version="1.0" encoding="UTF-8"?>
<!-- 执行方法名中包含Testd的方法 -->
<suite name="Regular Exp Suite" verbose="1">
<test name="Regular Exp Test">
<classes>
<class name="test.regularexppackage.RegularExpClass">
<methods>
<include name=".*Test.*" />
</methods>
</class>
</classes>
</test>
</suite>


increg-testng.xml 中增加如下配置信息


<?xml version="1.0" encoding="UTF-8"?>
<!-- 不执行方法名中包含Testd的方法 -->
<suite name="Regular Exp Suite" verbose="1">
<test name="Regular Exp Test">
<classes>
<class name="test.regularexppackage.RegularExpClass">
<methods>
<exclude name=".*Test.*" />
</methods>
</class>
</classes>
</test>
</suite>

选择对应的xml文件然后右击——run as 【TestNG Suite】检查执行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值