zoukankan      html  css  js  c++  java
  • testng 的常用注解

    常用注解如下:

    • @BeforeSuite: 此注解的方法会在当前测试集合中的任一测试用例前执行
    • @AfterSuite: 此注解的方法会在当前测试集合中的所有测试程序结束后执行
    • @BeforeTest: 此注解的方法在每个Test执行之前会运行
    • @AfterTest: 此注解的方法在每个Test执行之后会运行
    • @BeforeGroups: 此注解的方法在分组测试的任一测试用例执行之前会运行
    • @AfterGroups: 此注解的方法在分组测试的所有测试用例执行之后会运行
    • @BeforeClass: 此注解的方法会在当前测试类中的任一测试用例前执行
    • @AfterClass: 此注解的方法会在当前测试类中的所有测试用例结束后执行
    • @BeforeMethod: 此注解的方法会在当前测试中的每个方法开始之前执行
    • @AfterSuite: 此注解的方法会在当前测试中的每个方法开始之后执行
    • @Test: 表示一个测试用例

    注解运用的代码如下:

    package cn.gloryroad;
    
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.AfterSuite;
    
    public class Annotation {
      @Test
      public void test1() {
          System.out.println("***** test1 被执行 **********");
      }
      
      @Test
      public void test2() {
          System.out.println("********* test2 被执行 *********");
      }
      @BeforeMethod
      public void beforeMethod() {
          System.out.println("beforeMethod 被执行");
      }
    
      @AfterMethod
      public void afterMethod() {
          System.out.println("afterMethod 被执行");
      }
    
      @BeforeClass
      public void beforeClass() {
          System.out.println("beforeClass 被执行");
      }
    
      @AfterClass
      public void afterClass() {
          System.out.println("afterClass 被执行");
      }
    
      @BeforeTest
      public void beforeTest() {
          System.out.println("beforeTest 被执行");
      }
    
      @AfterTest
      public void afterTest() {
          System.out.println("afterTest 被执行");
      }
    
      @BeforeSuite
      public void beforeSuite() {
          System.out.println("beforeSuite 被执行");
      }
    
      @AfterSuite
      public void afterSuite() {
          System.out.println("afterSuite 被执行");
      }
    
    }

     测试结果如下

  • 相关阅读:
    初次学习Vue,输出Hello Vue!
    js的let语句在安卓手机端的QQ浏览器出错的问题
    前端框架的对比
    Vue环境搭建及node安装过程整理
    快速排序与冒泡排序(面试题)
    判断一个字符串中出现次数最多的字符并统计其出现的次数(面试题)
    Go_18: Golang 中三种读取文件发放性能对比
    GO_05_2:Golang 中 panic、recover、defer 的用法
    Go_17:GoLang中如何使用多参数属性传参
    Go_16:GoLang中flag标签使用
  • 原文地址:https://www.cnblogs.com/lanbing/p/9610357.html
Copyright © 2011-2022 走看看