Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

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);
    }
}
share|improve this answer
add comment

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)

share|improve this answer
    
Is there something like ReportNG for Junit4 ? –  djangofan Jun 27 '13 at 18:39
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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