Przykład dostawcy danych Java Testng

// You can set the dataprovider to be an array of Object and use ArrayList> to have your parameters in key value pairs.
@DataProvider
public Object[][] getTestData()
{
    List<HashMap<String, String>> arrayMapList = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> hashMapItems = new HashMap<String, String>();

    //use a loop to fill in all the parameter name and value pairs
    hashMapItems.put("parameterName1", "parameterValue");
    hashMapItems.put("parameterName2", "parameterValue");
    //--------------More put statements here------
    //finally add hash map to the list
    arrayMapList.add(hashMapItems);

    //Iterate the array list and store each HashMap object in an object array. First dimension is the iterator value.
    Object [][] hashMapObj = new Object [arrayMapList.size()][1];

    for(int i=0; i<arrayMapList.size() ; i++) {
        hashMapObj[i][0] = arrayMapList(i);
    }

    return hashMapObj;
}

// For each hashmap value in the array list, the test method will be run with its own set of parameters.
@Test (dataProvider = "getTestData", enabled = true)
public void testDataRead(HashMap<String,String> hashMapValue)
{
    System.out.println(hashMapValue.get(parameterNameKey));  //parameter 1
    System.out.println(hashMapValue.get(parameterNameKey));  //parameter 2
}
Scarlet Macaw