TestWatcher and TestNG

2019-07-20 13:08发布

All,

I use JUnit and TestWatcher along with Selenium (Java). Using TestWatcher upon failure and success, I place calls to a bug tracking tool API to lock test cases and defects.

I now want to generate a report of my Selenium test runs and lock the test cases and defects. I was thinking of using TestNG to generate reports but my TestWatcher won't work with TestNG.

I need some replacement of TestWatcher as i want to now replace junit with TestNG.

Anyone know anything like TestWatcher to use with TestNG?

Thanks.

1条回答
对你真心纯属浪费
2楼-- · 2019-07-20 13:42

You want to use an ITestListener (or more practically, a TestListener).

The official overview is: http://testng.org/doc/documentation-main.html#testng-listeners and the Javadoc is http://testng.org/javadocs/org/testng/ITestListener.html

To save you some time, you can extend a TestListenerAdapter, which will @Override all of the methods for you (so you only have to use the @Overrides you need).

Unlike JUnit, TestNG test listeners will be executed after your @Test method, and before your @AfterMethod. Also unlike JUnit, the Test Listener will have an ITestResult object passed in as a parameter, allowing you to access all of the fields and methods of your test class via Java reflection.

查看更多
登录 后发表回答