
上QQ阅读APP看书,第一时间看更新
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 {
...
- The JavaDoc for the iTestContext class is located at https://jitpack.io/com/github/cbeust/testng/master-6.12-gf77788e-171/javadoc/org/testng/ITestContext.html.
- The JavaDoc for the iTestResult class is located at https://jitpack.io/com/github/cbeust/testng/master-6.12-gf77788e-171/javadoc/org/testng/ITestResult.html.