简介

testng (testting next generation,下一代测试技术,一个单元测试框架)
提供了一系列丰富的注解,比junit更加强大,支持依赖测试,忽略测试,一场测试,超时测试等多种依赖场景。
pom依赖地址

  1. <!-- https://mvnrepository.com/artifact/org.testng/testng -->
  2. <dependency>
  3. <groupId>org.testng</groupId>
  4. <artifactId>testng</artifactId>
  5. <version>6.13.1</version>
  6. <scope>test</scope>
  7. </dependency>

TestNG常用注解

@Test 标记为常用方法
@BeforeMethod/AfterMethod 在某个测试方法执行之前,之后运行
@BeforeClass/AfterClass 在某个测试类所有开始之前,之后
@BeforeTest/AfterTest 在某个测试所有测试方法执行之前,之后
@BeforeSuite/AfterSuite 所有测试方法执行开始之前,结束之后

TestNG 注解的常用属性

忽略测试

当在测试过程中需要标记一个用例skip的时候,使用这个属性。
@Test(enabled = false)

超时测试

超时 表示如果自动化测试花费的时间超过指定的毫秒数,那么testng将会终止并将它标记为失败,在某些业务场景下,超时即失败的时候使用
@Test(timeout=100( 单位为毫秒

依赖测试

测试方法依赖于某些方法
@Test(dependsOnMethods={多个方法的情况下为一个方法名组成的数组})
方法执行顺序
step1 先执行被依赖的方法
step2 再一次执行没配置依赖的方法
step3 最后执行需要依赖的测试放啊

测试方法优先级

@Test(priority = 1)
执行优先级,数字越小优先级越高。

TestNG常用断言方式

Assert.assertTrue() 判断是否为true
Assert.assertFalse() 判断是否为alse
Assert.assertEquals() 判断是否相等

testng.xml配置文件