我有以下TestNG Java类:
public class TestSequence {
@BeforeTest
public void initialize() {
System.out.println("Inside initialize...............");
}
@Test(groups = { "group1", "group2" })
public void commonCase() throws Exception {
System.out.println("Inside commonCase...............");
}
@Test(groups = { "group1"}, dependsOnMethods = { "commonCase" })
public void group1A() throws Exception {
System.out.println("Inside group1A...............");
}
@Test(groups = { "group1"}, dependsOnMethods = { "group1A" })
public void group1B() throws Exception {
System.out.println("Inside group1B...............");
}
@Test(groups = { "group1"}, dependsOnMethods = { "group1B" })
public void group1C() throws Exception {
System.out.println("Inside group1C...............");
}
@Test(groups = { "group1"}, dependsOnMethods = { "group1C" })
public void group1D() throws Exception {
System.out.println("Inside group1D...............");
}
@Test(groups = { "group2"}, dependsOnMethods = { "commonCase" })
public void group2A() throws Exception {
System.out.println("Inside group2A...............");
}
@Test(groups = { "group2"}, dependsOnMethods = { "group2A" })
public void group2B() throws Exception {
System.out.println("Inside group2B...............");
}
@Test(groups = { "group2"}, dependsOnMethods = { "group2B" })
public void group2C() throws Exception {
System.out.println("Inside group2C...............");
}
@Test(groups = { "group2"}, dependsOnMethods = { "group2C" })
public void group2D() throws Exception {
System.out.println("Inside group2D...............");
}
}
这是我的testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="TestSequence">
<methods>
<include name="group1*"/>
<exclude name="group2*"/>
</methods>
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
我从命令行运行测试自动化,如下所示:
java -cp C:\TestProject\lib\*;C:\TestProject\bin org.testng.TestNG testng.xml
我得到的输出如下:
Inside initialize...............
Inside commonCase...............
Inside group1A...............
Inside group2A...............
Inside group1B...............
Inside group2B...............
Inside group1C...............
Inside group2C...............
Inside group1D...............
Inside group2D...............
为什么不排除group2测试用例,尽管testng.xml中注明了排除?
非常感谢您的回复。
答案 0 :(得分:0)
正如documentation所说:
注意:TestNG使用正则表达式,而不是wildmats。意识到 差异(例如,&#34;任何&#34;匹配&#34;。&#34; - 点星 - 而不是&#34; &#34;)。
所以,试着改变:
<methods>
<include name="group1*"/>
<exclude name="group2*"/>
</methods>
人:
<methods>
<include name="group1.*"/>
<exclude name="group2.*"/>
</methods>