0

I want to implement a custom reporter for TestNG xml test results. I currently use JUnitReportReporter. My result xml currently looks like this:

testcase name="testSearchForProductAndVerifyFirstFoundItem" time="55.516" classname="com.jpard.jaf.test.SearchForAnItemTests"

I simply want to replace testcase name with the Test Description as in @Test(description = "Test that first item in the results is the one searched for"). How can I do that in the simplest way possible. Many thanks!

Flup
  • 35
  • 2
  • 9

2 Answers2

1

I did it simple extending JUnitReportReporter class and overriding getTestName method to show in xml report method name and description. The class looks like this:

public class CustomReporter extends JUnitReportReporter {

@Override
protected String getTestName(ITestResult tr) {
    return tr.getMethod()
             .getMethodName() + ": " + tr.getMethod()
                                         .getDescription();
}

}

I hope it helps anyone looking for this issue.

Flup
  • 35
  • 2
  • 9
0

I think you'll have to implement IMethodInterceptor interface which will return a list of method instances , IMethodInstance and then from that list get all instances one by one and then

desc = instance.getMethod().getDescription();

method getDescription()

Have a look here

user1207289
  • 3,060
  • 6
  • 30
  • 66