TestNG介绍
一、测试人员使用的原因
1、比Junit涵盖功能更全面的测试框架
2、Junit更适合隔离性比较强的单元测试
3、TestNG更适合复杂的集成测试
二、TestNG基本注解与执行顺序
执行顺序为:
beforesuite->beforetest->beforeclass->beforemethod->aftermethod->afterclass->aftertest->aftersuite
举个栗子
package package1;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
public class NewTest {
@Test
public void test2() {
System.out.println("test2");
}
@Test
public void test1() {
System.out.println("test1");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("beforeMethod");
}
@AfterMethod
public void afterMethod() {
System.out.println("afterMethod");
}
@BeforeClass
public void beforeClass() {
System.out.println("beforeClass");
}
@AfterClass
public void afterClass() {
System.out.println("afterClass");
}
@BeforeTest
public void beforeTest() {
System.out.println("beforeTest");
}
@AfterTest
public void afterTest() {
System.out.println("afterTest");
}
@BeforeSuite
public void beforeSuite() {
System.out.println("");
}
@AfterSuite
public void afterSuite() {
System.out.println("");
}
}
输出的结果
beforeTest
beforeClass
beforeMethod
test1
afterMethod
beforeMethod
test2
afterMethod
afterClass
afterTest
如上代码中有2个test,查看输入,并非是按照顺序先执行test2再执行test1。原因是test执行顺序是按照a-z字母顺序执行,当存在相同字母时按照数字顺序执行。
未完。。。。。
网友评论