简体   繁体   English

为什么@DataProvider注释在TestNG中的@BeforeClass之前运行?

[英]Why is @DataProvider annotation runs before @BeforeClass in TestNG?

Using TestNG , why does the @DataProvider run before @BeforeClass ? 使用TestNG ,为什么@DataProvider@BeforeClass之前运行?

It seems that sometimes @DataProvider runs before @BeforeClass and some times not? 似乎有时候@DataProvider@BeforeClass之前运行而有时候@DataProvider运行?

Anybody knowing the reason? 谁知道原因?

这就是今天实施的方式,这对你来说是个问题吗?

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. BeforeClass annotation方法仅在第一个测试方法之前运行一次。 The Current Class method will be one from which it is invoked. Current Class方法将是调用它的方法。

@DataProvider @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. DataProvider annotation方法返回Object [] []类型值,其中每个Object []可以指定为希望从此DataProvider注释方法接收数据的测试方法的参数。

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 在beforeClass中
  • DataProvider Data(5, five) DataProvider数据(5,5)
  • DataProvider Data(6, six) DataProvider数据(6,6)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM