天天看點

testng基本注解執行順序

這篇文章介紹的注解包括@BeforeMethod/@AfterMethod、@BeforeClass/@AfterClass、@BeforeSuite/@AfterSuite

直接在BasicAnnotation 類右鍵,運作這個類

import org.testng.annotations.*;

public class BasicAnnotation {

    //最基本的注解,用來把方法标記為測試的一部分
    @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,這是在類運作之後運作的方法");
    }

    @BeforeSuite
    public void beforeSuite(){
        System.out.println("BeforeSuite測試套件");
    }

    @AfterSuite
    public void afterSuite() {
        System.out.println("AfterSuite測試套件");
    }
}

           

運作結果如下:

testng基本注解執行順序