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)中的所有测试程序运行结束之后执行");
    }
}

程序运行结果:

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

原文地址:https://www.cnblogs.com/xmmc/p/7489343.html