测试报告:
浏览器查看:
2.2.3 基础实例2
2.2.3.1 编写测试用例
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class TestngStudy {
// test case 1
@Test
public void testCase1() {
System.out.println("This is a test case 1");
}
// test case 2
@Test
public void testCase2() {
System.out.println("This is a test case 2");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("This is beforeMethod");
}
@AfterMethod
public void afterMethod() {
System.out.println("This is afterMethod");
}
@BeforeClass
public void beforeClass() {
System.out.println("This is beforeClass");
}
@AfterClass
public void afterClass() {
System.out.println("This is afterClass");
}
@BeforeTest
public void beforeTest() {
System.out.println("This is beforeTest");
}
@AfterTest
public void afterTest() {
System.out.println("This is afterTest");
}
@BeforeSuite
public void beforeSuite() {
System.out.println("This is beforeSuite");
}
@AfterSuite
public void afterSuite() {
System.out.println("This is afterSuite");
}
}
2.2.3.2 执行用例
[TestNG] Running:
C:UsersAlbertAppDataLocalTemp estng-eclipse--65898469 estng-customsuite.xml
This is beforeSuite
This is beforeTest
This is beforeClass
This is beforeMethod
This is a test case 1
This is afterMethod
This is beforeMethod
This is a test case 2
This is afterMethod
This is afterClass
This is afterTest
PASSED: testCase1
PASSED: testCase2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
This is afterSuite
===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
[TestNG] Time taken by org.uncommons.reportng.HTMLReporter@5f8ed237: 217 ms
以上TestNG学习基本了解完毕,下一篇将通过对气象局提供的天气接口的测试,来讲解HTTP接口的自动化测试,与结果断言。