APP接口自动化测试JAVA+TestNG(2)—TestNG简介与基础实例

发表于:2016-5-27 10:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Findyou    来源:51Testing软件测试网采编

分享:
  2.2.2.5 执行用例
  执行:右击JAVA文件,Run as -- > TestNG Test
  执行结果:
  测试报告:
  浏览器查看:
  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:\Users\Albert\AppData\Local\Temp\testng-eclipse--65898469\testng-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接口的自动化测试,与结果断言。
相关文章:
APP接口自动化测试JAVA+TestNG(1)—框架环境搭建
22/2<12
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号