testNg is ignoring parameterized tests with dataPr

2019-09-10 16:50发布

问题:

I am trying to run a parameterized test in testNg using dataProvider. But somehow it is always ignoring that test case. Below is the reference code:

@DataProvider(name = "test")
public Object[][] testDP() throws Exception {
    Object[][] arrayObject = getExcelData("TestData.xlsx", "TestData", "testName");
    return arrayObject;
}


@Test(dataProvider = "test", groups = {"sanity"})
public void testMethod(String testName, String logisticsHandler) {
    System.out.print(testName + "\n");
    setUpdateLogisticsHandler(logisticsHandler);
    updateLogisticsHandler(context.getAuthToken(),context.getQuoteIdForRfq());

}

回答1:

There are two ways of sending data to the test.

  1. Static Arrays usage - as suggested by Julien Herr
  2. If you are using the excel to get the data then in excel you must have exactly same number of rows/fields as in the @test function.

For Example: String testName, String logisticsHandler are two fields in your @test function then the excel must have ONLY two rows with the required fields testdata so that the ObjectArray will have these fields.

You can use Apache POI and handle this very easily.