測(cè)試報(bào)告:
瀏覽器查看:
2.2.3 基礎(chǔ)實(shí)例2
2.2.3.1 編寫測(cè)試用例
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 執(zhí)行用例
[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學(xué)習(xí)基本了解完畢,下一篇將通過對(duì)氣象局提供的天氣接口的測(cè)試,來講解HTTP接口的自動(dòng)化測(cè)試,與結(jié)果斷言。