| || |
What is the equivalent of ITestResult which belongs to testng in junit?
I am currently working on junit where I need the result of each test case. I know we can use ITestResult in NUnit but what is its equivalent in junit?
What is your goal for needing ITestResult? That is a very low level interface that's not consumed unless you're trying to modify the framework itself.
Originally Posted by bharath14
In Nunit, the preferred way of intercepting and modifying test results are through custom Action Attributes, NUnit - ActionAttributes You don't really touch the TestResults class, you work with hooks provided by the the Action attributes.
Similarly, in Java, the equivalent is the TestRule annotation, TestRule (JUnit API) There are several different Rule types you can extend, the most common is the TestWatchman. That will give you hooks to intercept different pass/fail events before they happen and you can modify the test results before they get published.
With TestNG you should be using Listeners. Cedric's book covers this somewhat but the best way is to actually try the code out.
TestNG Default Reports
TestNG comes with certain predefined listeners and by default they are added to the test execution. Whenever TestNG is run, HTML and XML reports are generated by default in the directory ./test-output.
For implementing a reporting class, the class has to implement an org.testng.IReporter interface. TestNG has its own reporter objects and these objects are called when the whole suite run ends. The object containing the information of the whole test run is passed on to the report implementations. The default implementations are:
Main – This is the main HTML reporter for suites. You can access the main report by opening index.html from test-output directory.
FailedReporter – This reporter is responsible for creating testng-failed.xml that contains just the test methods failed.
XMLReporter – TestNG offers an XML reporter capturing TestNG specific information that is not available in JUnit reports, creates testng-results.xml.
EmailableReporter2 – A reporter that generates one big HTML file emailable-report.html that’s easy to email to coworkers. If system property noEmailableReporter is set to some non-null value, the emailable report will not be generated.
JUnitReportReporter – It creates JUnit compatible XML file
SuiteHTMLReporter – This is the older version of HTML reporter for suites.
If we want only the custom reporters run then we make use of the flag –useDefaultListeners.