[英]Is there TestCaseSourceAttribute in TestNg similar to the one we have in Nunit
通过使用 TestCaseSourceAttribute,我们可以在 nunit 中使用一种测试方法进行多项测试。 TestNg有没有类似的选项?
TestNg 中最接近的概念是DataProvider 。 然而,这不是完全类比。
TestNg 不支持每个特定测试用例的数据提供程序参数化,就像您在 NUnit 中所做的那样
至少就像在 NUnit 中所做的那样,因为您可以通过向数据提供者逻辑引入一些额外的代码来解决这个问题。 然而,它似乎并不优雅。
但是,您可以使用官方 TestNg 示例中所示的数据来提供测试:
@DataProvider(name = "test1")
public Object[][] createData1() {
return new Object[][] {
{ "Cedric", new Integer(36) },
{ "Anne", new Integer(37)},
};
}
//This test method declares that its data should be supplied by the Data Provider
//named "test1"
@Test(dataProvider = "test1")
public void verifyData1(String n1, Integer n2) {
System.out.println(n1 + " " + n2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.