这两个注释都在testNG中的@test之前运行,然后它们之间有什么区别。

最佳答案

检查以下代码并输出

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Test_BeforeTestAndBeforeMethod {

    @BeforeTest
    public void beforeTest()
    {
        System.out.println("beforeTest");
    }

    @BeforeMethod
    public void beforeMethod()
    {
        System.out.println("\nbeforeMethod");
    }


    @Test
    public void firstTest()
    {
        System.out.println("firstTest");
    }

    @Test
    public void secondTest()
    {
        System.out.println("secondTest");
    }

    @Test
    public void thirdTest()
    {
        System.out.println("thirdTest");
    }
}

输出:
beforeTest

beforeMethod
firstTest

beforeMethod
secondTest

beforeMethod
thirdTest

关于testng - TestNG中的BeforeTest和BeforeMethod有什么区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50811759/

10-10 11:51