开发者

Why is @DataProvider annotation runs before @BeforeClass in TestNG?

开发者 https://www.devze.com 2023-01-17 18:46 出处:网络
Using TestNG, why does the @DataProvider run before@BeforeClass? It seems that sometimes @DataProvider runs before @BeforeClass and some ti开发者_运维问答mes not?

Using TestNG, why does the @DataProvider run before @BeforeClass?

It seems that sometimes @DataProvider runs before @BeforeClass and some ti开发者_运维问答mes not?

Anybody knowing the reason?


It's just the way it's implemented today, is this a problem for you?


Please find the sequence of execution below:

@BeforeSuite
@BeforeTest
@BeforeClass
@DataProvider
@BeforeMethod
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite


@BeforeClass

BeforeClass annotation Method runs only once before the first test method. The Current Class method will be one from which it is invoked.

@DataProvider

DataProvider annotation method returns an Object[ ][ ] type value, where each Object[ ] can be assigned as the parameter of the test method that wants to receive the data from this DataProvider annotation method.

public class TestNgDataProviderExample {
    @BeforeClass
    public void beforeClass() {
        System.out.println("in beforeClass");
    }
    @Test(dataProvider = "getData")
    public void instanceDbProvider(int p1, String p2) {
        System.out.println("DataProvider Data(" + p1 + ", " + p2 + ")");
    }

    @DataProvider
    public Object[][] getData() {
        return new Object[][] {{5, "five"}, {6, "six"}};
    }
}

Output:

  • in beforeClass
  • DataProvider Data(5, five)
  • DataProvider Data(6, six)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号