简体   繁体   中英

Is there TestCaseSourceAttribute in TestNg similar to the one we have in Nunit

We can have one test method in nunit for multiple tests by using TestCaseSourceAttribute. Is there any similar option in TestNg?

The nearest concept in TestNg is DataProvider s. However it is not complete analogy.

TestNg does not support parameterization of data provider for each particular test case like you can do in NUnit

At least as one would do in NUnit because you can work around that by introducing some extra code to the dataprovider logic. However it does not seem elegant.

However you can feed the tests with the data like shown in official TestNg example :

@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);
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM