DataProviders in TestNG are used when we need to iterate over objects. These can be objects created from Java that include complex objects, objects from a property file or database, or simple string objects. Whenever a dataProvider attribute is specified in a @Test annotation, and a method with the annotation @DataProvider exists, the data from this method is passed into the @Test annotated method as a two-dimensional object array.
Let's look at a small example, which is enhanced from our earlier example, where we extracted data into a list of HashMaps. Here we go a step further and read the list of HashMaps in a two-dimensional object array. The following code demonstrates this concept. The code has been split into ...