TestNG中的include/exclude屬性支持使用正則表達(dá)式,下面讓我們一起來學(xué)習(xí)其用法:新建一個(gè)java項(xiàng)目,如下結(jié)構(gòu)
RegularExpClass中增加如下代碼:
package test.regularexppackage;import org.testng.annotations.Test;public class RegularExpClass {@Testpublic void includeTestFirst(){System.out.PRint("First include test method");}@Testpublic void includeTestSecond(){System.out.print("Second include test method");}@Testpublic void excludeTestFirst(){System.out.println("First exclude test method");}@Testpublic void excludeTestSecond(){System.out.println("Second exclude test method");}@Testpublic void includeMethod(){System.out.println("Include method");}@Testpublic void excludeMethod(){System.out.println("Exclude method");}}
excreg-testng.xml中增加如下配置信息 (testNG 中任意字符的表示方法 .*)
<?xml version="1.0" encoding="UTF-8"?><!-- 執(zhí)行方法名中包含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"?><!-- 不執(zhí)行方法名中包含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>
選擇對(duì)應(yīng)的xml文件然后右擊——run as 【TestNG Suite】檢查執(zhí)行結(jié)果
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注