TestNG 的示例代碼
TestNG 提供了從命令行運行測試用例的方法。下面將首先從命令行運行測試用例。假設有如下的測試用例組:
列表 1. TestNG 示例代碼
package example1;
import org.testng.annotations.*;
public class SimpleTest {
@Configuration(beforeTestClass = true)
public void setUp() {
// code that will be invoked when this test is instantiated
}
@Test(groups = { "HelloWorld" })
public void helloWorldTest() {
System.out.println("Hello World");
throw new Error();
}
@Test(threadPoolSize = 10, invocationCount = 5, timeOut = 1000, groups = { "multiple" })
public void multiThreadTest() {
System.out.println("MultiThread test");
}
@Test(groups = { "HelloNature" })
public void helloNatureTest() {
System.out.println("Hello Nature");
throw new Error();
}
}
運行 TestNG 的 Ant 腳本
為了運行這組測試用例,構建了如下的 Ant 運行腳本:
列表 2. 運行測試用例組的 Ant 腳本 build.xml 文件
<project default="test">
<path id="cp">
<pathelement location="c:/spark/eclipse/plugins/org.testng.eclipse_4.7.0.0/lib/testng-jdk15.jar"/>
<pathelement location="c:\"/>
</path>
文章來源于領測軟件測試網 http://www.kjueaiud.com/