Building the test listener class

To simplify getting started, the new test listener class can extend TestNG's TestListenerAdapter class, providing the collection of test results to the class, which can then be customized, override default methods where necessary. Some of the methods that can be customized include:

  • onStart(ITestContext testContext)
  • onFinish(ITestContext testContext)
  • onTestStart(ITestResult tr)
  • onTestSuccess(ITestResult tr)
  • onTestFailure(ITestResult tr)
  • onTestSkipped(ITestResult tr)
  • onConfigurationSuccess(ITestResult tr)
  • onConfigurationFailure(ITestResult tr)
  • onConfigurationSkip(ITestResult tr)

The other TestNG classes used by this listener class are the iTestContext and iTestResult interfaces, which provide data on the number of tests, stats on passed, failed, skipped, test method names, times, groups, suites, output directories, status, parameters, classes, context, and so on. This data can then be logged in a formatted context to the console, or to a log file:

/**
* TestNG TestListener Class
*
*/
public class TestNG_Listener extends TestListenerAdapter {
...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.186.19