Dynamic test name from data driven excel

Viewed 82

I use in my framework testNG with Data driven. All test data are taken from excel table and DataDriven return them as a two dimensional array e.g. Data[][].

My code looks like:

@Test (DataDriven = "data")
public void testCase(Sting testName, String testData1, String results){
    String s = doSomething(testData1);
    Assert.assertTrue(s, results);

This is only an example, but every test parameter I got from excel column. I would like to add to testate name a name from testName parameter. Is it even possible? I use additionally Listener with ITestListener interface.

1 Answers

You could use the ITestContext to set the test name.

@Test(dataProvider = "data")
public void testCase(ITestContext ctx, Sting testName, String testData1, String results){
    ctx.getCurrentXmlTest().setName(testName);  
    String s = doSomething(testData1);
    Assert.assertTrue(s, results);
}
Related