Providing TestNG factory with data provider to invoke test methods - Not able to invoke test multiple times
Actually it looks like the Factory
method is not required in this case. Since the whole list is passed as a single test case, the test is only executed once. You need to convert the list into an Object[][]
where each test case would be a Map
:
Either you could pass it as:
return new Object[][]{ {hash_map}, {hash_map1}};
OR if there are lot of maps in the list or if the list is populated from a different source, then you could do the following stream operation (if you are using java 8 or above). (If you are using a version below java 8, then you could use a for loop to do the same)
At the end of the data provider:
return check.stream() .map(m -> new Object[] { m } ) .toArray(Object[][]::new);
Instead of using a factory you could modify the test as:
@Test(dataProvider = "create")public void test(HashMap<String, String> map) { System.out.println("ID is " + Thread.currentThread().getId()); System.out.println(map);}