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 被执行");
      }
    
    }

     测试结果如下

  • 相关阅读:
    从零开始PHP学习
    从零开始PHP学习
    从零开始PHP学习
    从零开始PHP学习
    从零开始PHP学习
    [暂停一天]从零开始PHP学习
    [Laravel 5] 表单验证 Form Requests and Controller Validation
    JQuery 在$(window).load() 事件中 不运行 $(window).resize()
    JS计算两个日期相差几天
    python 学习之Windows 下的编码处理!
  • 原文地址:https://www.cnblogs.com/lanbing/p/9610357.html
Copyright © 2011-2022 走看看