Created
August 8, 2017 05:57
-
-
Save sahajamit/8ac61d6b8af4aa2640ce1351b3ede8ce to your computer and use it in GitHub Desktop.
TestNG dataprovider example to pass List of maps as a provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testng; | |
import org.testng.annotations.DataProvider; | |
import org.testng.annotations.Test; | |
import java.util.*; | |
public class testngListOfMaps_DataProvider { | |
@DataProvider(name = "Passing List Of Maps") | |
public Iterator<Object[]> createDataforTest3() { | |
List<Map<String,String>> lom = new ArrayList<Map<String,String>>(); | |
Map<String,String> map1 = new HashMap<String,String>(); | |
Map<String,String> map2 = new HashMap<String,String>(); | |
map1.put("name","Amit"); | |
map2.put("name","Sarbjit"); | |
lom.add(map1); | |
lom.add(map2); | |
Collection<Object[]> dp = new ArrayList<Object[]>(); | |
for(Map<String,String> map:lom){ | |
dp.add(new Object[]{map}); | |
} | |
return dp.iterator(); | |
} | |
@Test(dataProvider = "Passing List Of Maps") | |
public void test1(Map<String,String> map){ | |
System.out.println("Value in first Map:" + map.get("name")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks A Lot Amit for this snippet.