I use Selenium webdriver 2 with Test-NG. Test-NG gives a nice report when an assertion fails. The customer wishes to see the same report in the case where an assertion passes. Is it possible to do with the default Test-NG reporter?

4 Answers 4


TestNG knows nothing about assertions per se. It knows only that the test threw an exception or did not. All of the information that TestNG gets from the assertion comes from the exception thrown by the assertion failure. If an assertion passes, TestNG never knows about it.

On the other hand, you can write your assertion methods that know how to log information, or to write information through TestNG's Reporter object. There may be other ways that an assertion can send information to TestNG, but each of them involves using some form of assertion that knows when and how to report the information.

One possibility is to write your own assertThat() method, like the one that comes with the Hamcrest library. The assertThat() method takes two parameters, a subject and a matcher. The matcher knows how to describe itself. You could write your assertThat() so that when the match succeeds, it describes the subject and the matcher to TestNG somehow (e.g. through the Reporter).

One possible implementation:

package my.package.name.MyAssertion;

public class MyAssertion {

    public static <T> boolean assertThat(T subject, Matcher<? super T> matcher) {
        MatcherAssert.assertThat(subject, matcher); // Calls the Hamcrest asserThat

        // If we get here, the Hamcrest assertion passed. Log it to TestNG.
        // You'll have to figure out how to write this method.
        reportMatchToTestNG(subject, matcher);

You can use ExtentReport.

You can use it to log your test steps and once its done it will generate a report to show your results. It will also show all fails and help you distinguish between assertion and an actually test fail. This is why we implemented it into our enviornment.

Here is how to set up ExtentReports on your project with examples - http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/

The above is a Logger method. You must put a log into each test step in your test code.

An easier but more restritive way of using ExtentReport is as a listener. You can use it to listen in on your tests as they are being executed. You must just specify the listener class in your test XML file.

Example - http://www.ontestautomation.com/using-the-extentreports-testng-listener-in-selenium-page-object-tests/

The reports generated by ExtentReport are extremly attractive and informative. There is huge support from the creators of this technology and as its open source they are more than willing to accept ideas for future updates etc.

You must use it in conjunction with a test runner eg. TestNG or JUnit.

Here is an example of a report generated by ExtentReport - http://relevantcodes.com/Tools/ExtentReports2/ExtentJava.html

Hope it helps !


If your output from Selenium Webdriver is in JUnit format, you can use ReportNG to format it to the way you need it.

If you are not currently outputting the your results in JUnit format, you will need to configure ant to output the reports in XML format (as per this link)

  • Is there something like ReportNG for Junit4 ?
    – djangofan
    Commented Jun 27, 2013 at 18:39

First, I would try to explain to the customer an assertion is a Boolean condition; if the assertion isn't hit then it "passes." Or perhaps ask the customer if they want to "see" what condition each Boolean expression is evaluating and log the condition.

I am not familiar with TestNG, but if they are persistent, then TestNG provides multiple assertion methods including:

  • public static void assertTrue(boolean condition, java.lang.String message) and
  • public static void assertTFalse(boolean condition, java.lang.String message)

This would certainly skew the report and appear to have lots of failures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.