zoukankan      html  css  js  c++  java
  • TestNG框架基础用法汇集

    昨晚加了一个通宵,困了就在小床上躺躺,结果今天白天全身疼,睡也睡不着,干脆坐起来写写文档。

    一:TestNG常用注解简介

    二:常用注解基础测试用例集合(JAVA版本)

    package com.testng.webdriver;
    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 testCase1()
        {
            System.out.println("测试用例1被执行");
        }
        
        @Test
        public void testCase2()
        {
            System.out.println("测试用例2被执行");
        }
        
        @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:在测试类中的Test开始运行前执行");
        }
        
        @AfterTest
        public void afterTest()
        {
            System.out.println("afterTest:在测试类中的Test运行结束后执行");
        }
        
        @BeforeSuite
        public void beforeSuite()
        {
            System.out.println("beforeSuite:在当前测试集合(Suite)中的所有测试程序开始运行之前执行");
        }
        
        @AfterSuite
        public void afterSuite()
        {
            System.out.println("afterSuite:在当前测试集合(Suite)中的所有测试程序运行结束之后执行");
        }
    }

    程序运行结果:

    每个注解的方法类如果被调用,均会打印出其对应的注解含义,从执行的结果可以分辨出不同的注解方法会在何时被调用,可以多看看这个实例,了解一下注解的执行含义。

  • 相关阅读:
    self 和 super 关键字
    NSString类
    函数和对象方法的区别
    求两个数是否互质及最大公约数
    TJU Problem 1644 Reverse Text
    TJU Problem 2520 Quicksum
    TJU Problem 2101 Bullseye
    TJU Problem 2548 Celebrity jeopardy
    poj 2586 Y2K Accounting Bug
    poj 2109 Power of Cryptography
  • 原文地址:https://www.cnblogs.com/xmmc/p/7489343.html
Copyright © 2011-2022 走看看