您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > TestNG
APP接口自动化测试JAVA+TestNG(2)?TestNG简介与基础实例
作者:Findyou 发布时间:[ 2016/5/27 14:40:35 ] 推荐标签:单元测试工具 软件测试

  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: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接口的自动化测试,与结果断言。

相关链接:
上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd