As per the TestNG doc, the Data provider must return Object[][] or Iterator<Object[]>. I have created Data provider method with the return type as Iterator. An example is as below -
@DataProvider(name = "airlineData")
public Iterator<Airline> getCreateAirlineData() throws IOException {
List<LinkedHashMap<String, String>> excelDataAsListOfMap = ExcelUtils.getExcelDataAsListOfMap("CreateAirlineData", "Sheet1");
List<Airline> airlineData = new ArrayList<>();
for(LinkedHashMap<String,String> data : excelDataAsListOfMap) {
Airline airline = Airline.builder()
.id(Integer.parseInt(data.get("Id")))
.name(data.get("Name"))
.country(data.get("Country"))
.logo(data.get("Logo"))
.established(data.get("Established"))
.website(data.get("Website"))
.slogan(data.get("Slogan"))
.head_quaters(data.get("HeadQuarter"))
.build();
airlineData.add(airline);
}
return airlineData.iterator();
}
I am using Data Provider method in Test as
@Test(dataProvider = "airlineData" )
public void createAirlineAndVerify(Airline airline) {
Response response = createAirline(airline);
}
As per my understanding return type, Iterator is not correct as per documentation. But tests run fine and it does not show any compilation error. But in IntelliJ, I noticed that it shows red as return type but runs the tests successfully.
Could someone please help me to understand this behavior here?
Well, I believe there is some outdated documentation for TestNg.
As I can see from TestNg sources, it successfully handles the cases like yours by automatic conversion to a proper format:
Which results in:
P.S. - What you can see in red in your IDE is probably caused by TestNg plugin that uses the rules from docs to highlight problematic code (which in fact is not problematic at all).