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

     测试结果如下

  • 相关阅读:
    YARN调度器(Scheduler)详解
    eaysui datagrid编辑时表格变宽变形问题解决
    超简单!两步实现Wordpress评论微信通知~
    基于混合模型的语音降噪效果提升
    无线路由器,86式墙壁路由器,连接时,子路由器不能上网
    vue 动态绑定NavMenu 导航菜单(两级)
    SVN代码迁移至Gitlab(保留日志)
    Spring Boot 获取项目路径或文件
    Spring Boot使用 @Async 注解进行异步调用
    【DVWA】安全测试工具之BurpSuite
  • 原文地址:https://www.cnblogs.com/lanbing/p/9610357.html
Copyright © 2011-2022 走看看