2

If my TestNG DataProvider has some logic in it, but then it results in an empty Object[][], I would like TestNG to count this as a failed test. I would prefer to not have to put logic in the DataProvider which checks that the Object[][].length > 0 since my package has many of these types of DataProviders. Is it possible to have TestNG mark myTest as Failed or at least Skipped?

@DataProvider(name = "emptyDataProvider")
public Object[][] emptyDataProvider() {
    // Some misc logic...
    return new Object[][] { };
} 

@Test(groups = {"beta"}, dataProvider = "emptyDataProvider")
public void myTest(final String param1) {  

    // some assertions
}
ngflanders
  • 21
  • 2

2 Answers2

0

If I can recall correctly if your data provider returns null object ie. with Zero Test Data you will see error stating the Data Provider returned a null value during execution.

Test will be marked as Failed as well. This is the default testNG behavior.

To handle it internally, you have to enter the logic in Data Provider method itself because once the empty Object[][] is returned, execution will fail instantly.

Kovid Mehta
  • 531
  • 2
  • 8
  • 28
0

The answer is yes...we can check the data provider some tricky we can use it...@BeforeClass you can check the data provider value and throws the throw new SkipException("Data Provider is null or empty!!!!!!!!!!");then create the custom report you can customizing the report @AfterTest you can use it and using Assert.fail() you can fail manually....

Karthi C
  • 31
  • 6