I try to execute the simple test case which call dataProvider and this dataProvider has return type as Iterator<Object[]>
, I know this return type is not accept by @DataProvider
method but after excute the below programm i get the blank output nothing is display in colsole,i accept at least message like the dataProvider is not exsist,please refer below program.
public class Practice {
@Test(dataProvider="NotWorking")
public void testCase(Object[] obj)
{
System.out.println(obj[0]);
System.out.println(obj[1]);
}
@DataProvider(name="NotWorking")
public Iterator<Object[]> dataProvider2()
{
List<Object[]> obj =new ArrayList<Object[]>();
Object[] obj1=new Object[2];
obj1[0]=new String("First_Object_First_value");
obj1[1]=new String("First_Object_Second_value");
Object[] obj2=new Object[2];
obj2[0]=new String("Second_Object_First_value");
obj1[1]=new String("Second_Object_Second_value");
Iterator<Object[]> itr = obj.iterator();
return itr;
}
}
i get the below output for above code,
[RemoteTestNG] detected TestNG version 7.4.0
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
Your statement
This is actually NOT correct.
Iterator<Object[]>
is an ACCEPTED return type for a dataProvider in testNG.So what is wrong with the above code is that, you are returning an empty
Iterator
. Note the changes in the below code:Now, after making the above changes, your test would work fine.
NOTE: A test method will not be invoked if the data to that method is empty.
So next question - Why was the test was marked as ran but did not print anything.
Answer: This depends on how an empty iterator is handled by testNG. There is a difference between versions
7.3.0
and7.4.0
itself. It would output asTest run : 0
for7.3.0
and asTest run : 1
for7.4.0
. There has been code changes in logging as part of the7.4.0
. The test method count for7.4.0
is taken from test contextcontext.getAllTestMethods()
, which contains the test you are running. For7.3.0
it is taken from an arraym_allTestMethods
(which is empty).