testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

Data provider mismatch for data provider with signature "Iterator<Object> dataProviderMethod(Method m)" #1278

Closed AndreyMatveyev closed 6 years ago

AndreyMatveyev commented 7 years ago

TestNG Version

6.10.0.201612030230

Expected behavior

For data provider with signature public static Iterator<Object> myDataProvider(Method m) the test method with signature public void myTestMethod(TestCaseData testCaseData) should work as it worked before in the previous version of TestNG 6.9.13.201609291640

Actual behavior

For data provider with signature public static Iterator<Object> myDataProvider(Method m) the test method with signature public void myTestMethod(TestCaseData testCaseData) fails with error "data provider mismatch" the same implementation works fine with previous version of TestNG 6.9.13.201609291640

notes:

Is the issue reproductible on runner?

Test case sample

Please, share the test case (as small as possible) which shows the issue

krmahadevan commented 7 years ago

@AndreyMatveyev

I used a sample which looks like below with TestNG 6.10 and I am not able to reproduce the issue.

public class Github1278 {
    @DataProvider
    public Iterator<Object[]> getData(Method method) {
        List<Object[]> objects = new ArrayList<>();
        objects.add(new Object[]{new Student("Jack")});
        objects.add(new Object[]{new Student("Jill")});
        objects.add(new Object[]{new Student("Rambo")});
        objects.add(new Object[]{new Student("Sherkhan")});
        return objects.iterator();
    }

    @Test(dataProvider = "getData")
    public void testMethod(Student s) {
        URL url = TestNG.class.getProtectionDomain().getCodeSource().getLocation();
        String version = new File(url.getFile()).getParentFile().getName();
        System.err.println("Running with TestNG " + version);
        Assert.assertNotNull(s.getName());
    }

    public static class Student {
        String name;

        public Student(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }
}

Here's the output I see:

Running with TestNG 6.10
Running with TestNG 6.10
Running with TestNG 6.10
Running with TestNG 6.10

===============================================
Default Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
AndreyMatveyev commented 7 years ago

Thank you for the quick turnaround. We'll try to replicate it in our environments again by using our code and the test code provided in the issue. Just one note; in the provided test which replicates the issue the signature is different comparing to the original case. The test uses public static Iterator<Object[]> myDataProvider(Method m) and the original code uses public static Iterator<Object> myDataProvider(Method m)

krmahadevan commented 6 years ago

Closing this issue since there's no update from the user. Please comment if this is still a problem.