0

I've been playing about with RestAssured and started using data providers for data driven tests. I'm currently getting a data provider mismatch error. I'm assuming it will be because im passing in a string or perhaps my api endpoint is incorrect? Also and this may be a different thread altogether. If I wanted to match my response to all of the records in this case 1000 is there a better way to check all 1000 records instead of a few?

public class test extends enablers {

@DataProvider
public Object[][] getData() {
    return new Object[][]{{24, "27.110.128.25", "Fuling" },
            {145, "212.132.237.53", "Muruni" }};
}



@Test(dataProvider = "getData")
public void GetUserId(String data, int userId, String ipAddress, String expectedCity) {

    given().
            pathParam("id", userId).pathParam("ip_address", ipAddress).
            when().
            get(id).
            then().
            assertThat().
            body(("id[0].'city'"), equalTo(expectedCity));

}
}

   org.testng.internal.reflect.MethodMatcherException: 
Data provider mismatch
Method: GetUserId([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=int, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.Integer)24,(java.lang.String)27.110.128.25,(java.lang.String)Fuling]

    at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:52)
    at org.testng.internal.Invoker.injectParameters(Invoker.java:1278)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1171)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:756)
    at org.testng.TestRunner.run(TestRunner.java:610)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
    at org.testng.TestNG.runSuites(TestNG.java:1133)
    at org.testng.TestNG.run(TestNG.java:1104)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)


Test ignored.

===============================================
Default Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

Here's my endpoint

    String id = "http://bpdts-test-app-v2.herokuapp.com/user/{id}/{ip-address}";

1 Answers1

0

Your dataprovider should be like

@DataProvider(name="getData")
public Object[][] getData() {
    return new Object[][]{{24, "27.110.128.25", "Fuling" },
            {145, "212.132.237.53", "Muruni" }};
}

Your test annotation will look dataprovider based on the @DataProvider name attribute not based on method name

so that your code will be like

public class test extends enablers {
    
    @DataProvider(name="getData")
    public Object[][] getData() {
        return new Object[][]{{24, "27.110.128.25", "Fuling" },
                {145, "212.132.237.53", "Muruni" }};
    }
    
    
    
    @Test(dataProvider = "getData")
    public void GetUserId(String data, int userId, String ipAddress, String expectedCity) {    
        given().
                pathParam("id", userId).pathParam("ip_address", ipAddress).
                when().
                get(id).
                then().
                assertThat().
                body(("id[0].'city'"), equalTo(expectedCity));    
    }
}

Your dataprovider returns 3 object whereas your test method need 4 values since it has four arguments.try by updating required data in your dataprovider which should return object of length 4 like

@DataProvider(name="getData")
    public Object[][] getData() {
        return new Object[][]{
                //Add required userid in place of 2
                //And 24,145 should be string
                {"24",2,"27.110.128.25", "Fuling" },
                {"145",2,"212.132.237.53", "Muruni" }
        };
     }

And your first value need to be string in place of 24 and 145

  • Yeah that sort of works now. just getting a 404 error on the body of the test it's not recognising the endpoint it seems I think it's the way im trying to search for the city in the Id's – Peter Kirby Aug 19 '20 at 09:05
  • @PeterKirby It is the error displayed based on your API documentation not from the java. Kindly upvote or mark it has accepted if it helped you since your dataprovider issue has been resolved – Mohamed Sulaimaan Sheriff Aug 19 '20 at 09:08
  • java.lang.AssertionError: 1 expectation failed. XML path id[0].'city' doesn't match. Expected: Fuling Actual: – Peter Kirby Aug 19 '20 at 09:52