1.4. Example of ITestListener

1.4. Example of ITestListener



ITestListener has methods on following events:
  • onStart is invoked after the test class is instantiated and before any configuration method is called
  • onTestSuccess is invoked on success of a test
  • onTestFailure is invoked on failure of a test
  • onTestSkipped is invoked whenever a test is skipped
  • onTestFailedButWithinSuccessPercentage is invoked each time a method fails but is within the success percentage requested.
  • onFinish is invoked after all the tests have run and all their Configuration methods have been called.
TestListenerExample is our test class. It has a @BeforeTest and an @AfterTest method. It has four test methods:
  1. testcase1() is expected to run fine
  2. testcase2() is expected to fail as it doesn’t throw the expected exception
  3. testcase3() receives a parameter but since we haven’t set a DataProvider, it is skipped
  4. testcase4() is invoked five times, of which, twice its going to fail. We have set the expected successPercentage to 50.
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.