英文:
Can I have TestNG fail/skip if the DataProvider provides no test cases?
问题
如果我的 TestNG DataProvider 中包含一些逻辑,但最终导致一个空的 Object[][]
,我希望 TestNG 将其视为一个失败的测试。我希望 不 必须在 DataProvider 中放置检查 Object[][].length > 0
的逻辑,因为我的代码包中有许多这种类型的 DataProvider。是否可以让 TestNG 将 myTest
标记为失败,或者至少标记为跳过?
@DataProvider(name = "emptyDataProvider")
public Object[][] emptyDataProvider() {
// 一些杂项逻辑...
return new Object[][] { };
}
@Test(groups = {"beta"}, dataProvider = "emptyDataProvider")
public void myTest(final String param1) {
// 一些断言操作
}
英文:
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
}
答案1
得分: 0
如果我记得正确的话,如果您的数据提供程序返回空对象,即零测试数据,您将会看到错误提示,指出数据提供程序在执行期间返回了空值。
测试也将被标记为失败。这是默认的TestNG行为。
要在内部处理它,您必须在数据提供程序方法中输入逻辑,因为一旦返回空的Object[][],执行将立即失败。
英文:
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.
答案2
得分: 0
答案是肯定的...我们可以检查数据提供者,有一些技巧可以使用它...在@BeforeClass中,您可以检查数据提供者的值,并抛出throw new SkipException("数据提供者为空或为空!!!!!!");然后创建自定义报告,您可以自定义报告,在@AfterTest中,您可以使用它,并且使用Assert.fail()可以手动失败...
英文:
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....
专注分享java语言的经验与见解,让所有开发者获益!
评论