问题
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 ITestResul
t 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