Search code examples
testngtestng-dataprovider

why data provider in testng returns 2D object array?


I am working on testNg these days but I have no idea what was design idea to return 2D object array in data provider method.


Solution

  • As I can understand from your question, you want to know why data provider needs 2 dimensional object array. Here I am referencing TestNg official documentation. Please have a look.

    https://testng.org/doc/documentation-main.html#parameters-dataproviders

    And they mentioned:

    An array of array of objects (Object[][]) where the first dimension's size is the number of times the test method will be invoked and the second dimension size contains an array of objects that must be compatible with the parameter types of the test method

    The reason is quite simple as we get test data in forms of rows and columns so that we need 2D object (object type because we are free to pass any type data String, int etc.) array.

    I hope it will help.