Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Selenium webdriver 2.0 in JUnit framework. I need to generate a report on my tuned both (positive and negative) test cases.

NOTE: We have an option to generate report by default in "TESTNG" framework. I need a solution to create in JUnit.

share|improve this question

You didn't say whether you were using Ant or something else. I will assume you are more interested in the "positive and negative" part of the question than how to invoke the JUnit test runner from your build tool.

You can register a TestWatcher to monitor what happens during a test run. The JUnit test runner will invoke methods on the TestWatcher when significant events occur. You can override those methods to insert logging code for passing/failing tests. Here is some sample code:

import org.junit.Assert;
import org.junit.Test;
import org.junit.Rule;
import org.junit.runner.Description;
import org.junit.rules.TestWatcher;
public class positive {   
    public TestWatcher watchman = new TestWatcher() {
        protected void failed(Throwable e,Description d) {
        System.out.println("FAILED: "+d.getClassName()+"."+d.getMethodName());

    protected void succeeded(Description d) {
        System.out.println("PASSED: "+d.getClassName()+"."+d.getMethodName());

    public void fails() {"I am a failure");

    public void passes() {

When you run that from the command line, you will see something like this:

$ java -cp $HOME/software/junit/target/*:$HOME/software/junit/lib/*:$PWD org.junit.runner.JUnitCore positive
JUnit version 4.12-SNAPSHOT
.PASSED: positive.passes
.FAILED: positive.fails
Time: 0.007
There was 1 failure:
1) fails(positive)
java.lang.AssertionError: I am a failure
    at positive.fails(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(

Tests run: 2,  Failures: 1
share|improve this answer

With Junit you can use ant to generate the reports in a html file. you have to configure the build.xml in ant to get the results in html.

share|improve this answer
and here is the and task to do this - – Tarun Nov 26 '13 at 8:38

Your Answer


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.