How to delete data only after all tests, based on inputs from data provider, are run?

我怕爱的太早我们不能终老 提交于 2019-12-11 16:56:26

问题


I've a test with different inputs, hence used @DataProvider but before inputs, from Object[][], passed to a test, I want to create some data which is common to test with all different inputs

@DataProvider(name = "test")
public Object[][] createData() {
    //create some data which is common for both john and bob
    return new Object[][] { { "john" }, { "bob" } };
}

@Test(dataProvider = "test")
public void userOp(String name) {
    //Perform some operations with user mention in `name`. For now let's just print the names
    System.out.println(name);
}

Once ALL tests, with different inputs(ie. john and bob) are run, I want to delete data that I created in data provider method.

NOTE I can use @AfterClass to delete this data but that can mess my other tests in test class hence I want to delete data, once I'm done with the test, for which it was created.

Can someone suggest how this can be achieved?


回答1:


Declare @AfterMethod with ITestResult parameter. In ITestResult you can find exact parameters used in your test method and delete related data. In @AfterClass just delete you common data.



来源:https://stackoverflow.com/questions/44309689/how-to-delete-data-only-after-all-tests-based-on-inputs-from-data-provider-are

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!