Pre-requisite: TestNG已安裝
1. 在測試方法中加入分組信息:
public class FirstTest {
@Before
public void testCase0() throws Exception {
......
}
@Test(groups = { "func" })
public void testCase1() throws InterruptedException {
......
}
@Test(groups={ "perf" })
public void testCase2() {
......
}
@After
public void testCase3() {
}
}
2. 修改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">
<groups>
<run>
<include name="perf" />
</run>
</groups>
<classes>
<class name="FirstTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
3. 在工程上右鍵點擊testng.xml->run as testng.
testCase0, testCase2, testCase3將被執行。