Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Saturday, February 26, 2011

Generate JUnit report with Ant & Eclipse IDE


Reports are crucial for any tests carried out.

Steps to configure and generate the test result from java eclipse using Ant:

this post is for users who have already familiar with java and eclipse.

Generating the ANT build:
Right click on the project and
select Export --> Ant Buildfiles.-->Next-->Select the project-->Finish.

Configuring jar:

Select Windows menu-->Preference -->Global Entries -->Add External JARs-->Select the folder where the eclipse is installed. eclipse -->Plugin -->Currently its located in "org.junit_4.8.1.v4_8_1_v20100427-1100"-->"junit.jar"-->OK.

Run the Ant Build:


Create a folder "junit" in side the project folder.

Right click on the AntBuildfile-->RunAs -->AntBuild

Return to java project and run as junit test.

End of test run you will find the test result in a html file named as index.html it will be stored inside the junit folder.
automationwithselenium.blogspot.com-Google pagerank and Worth

15 comments:

  1. Hello Sir,

    I followed all the steps provided here.

    I ran the AntBuild and it was successful. Then i ran the project but i don't see any index.html file under the junit folder.

    Can you help?

    ReplyDelete
  2. I get the result now. But is there a way i can view all the assertions those have passed and failed. Because this result just pass or fail a entire function not individual checks.

    ReplyDelete
    Replies
    1. I followed the steps too but cant see result . Can you tell me how you were able to get file in junit folder. Mine is empty.

      Delete
    2. @Pokhriyal

      Can you let us know what are your settings ??

      Delete
    3. Nayak how did you the results. my junit folder is blank. please be advice.

      Delete
  3. Thanks, this was quite helpful. I'm using Eclipse Helios. I added some changes/details to your description which do apply at least for Helios:

    Generating the ANT build:
    Right click on the project and select:
    Export
    -> General -> Ant Buildfiles -> Next
    -> Select the project (is already selected)
    -> Finish.
    Now "build.xml" is generated in the project folder

    Configuring JUnit.jar:
    This step wasn't necessary for me, however here is where you could add the "junit.jar" in case you have to:
    Select:
    Windows menu
    -> Preferences
    -> Ant -> Runtime -> Global Entries
    -> Add External JARs
    -> in Eclipse install directory: "eclipse/plugins/org.junit_4.8.1.v4_8_1_v20100427-1100/junit.jar"
    -> ok

    Run the Ant Build:
    Create a folder "junit" inside of the project folder.
    Right click on the "build.xml"
    -> RunAs -> AntBuild...
    -> check all single JUnit test classes and the junitreport entry
    -> Run
    Right click the "junit" directory and select Refresh in the context menu (or press F5).
    You will find the test results in "junit".
    Open "junit/index.html".

    (Running the tests "as JUnit Test" is not necessary)

    ReplyDelete
  4. I did everything that is said here.

    Am using Eclipse + TestNG.

    Running as AntBuild says "Build Successfull"

    But when I run TestNG. The JUNIT folder is still empty.

    Please help.

    ReplyDelete
    Replies
    1. It would be ideal to redo it once again .. as many have followed the same steps & worked fine for them.

      You must be missing something trivial

      Delete
  5. I get the following error when I run the ANT build:

    [junitreport] Loading stylesheet jar:file:/C:/Eclipse/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
    [junitreport] : Error! The first argument to the non-static Java function 'replace' is not a valid object reference.
    [junitreport] : Error! Cannot convert data-type 'void' to 'reference'.
    [junitreport] : Fatal Error! Could not compile stylesheet
    [junitreport] Failed to process C:\Documents and Settings\Administrator\workspace\Home\junit\TESTS-TestSuites.xml

    ReplyDelete
    Replies
    1. There are some references which you are missing .

      Can you post your build.xml file & also ensure you have added all necessary jars please

      Delete
    2. The Eclipse Bug is clearly documented Bug 384757. The analysis suggests that Oracle introduced the bug.

      https://bugs.eclipse.org/bugs/show_bug.cgi?id=384757

      If you are using Eclipse/JUnit report with JDK 1.7, please use JDK 1.6. There is a bug in JDK 1.7 with Eclipse/JUnit report similar to what you describe.

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Hi,
    Worked absolutely fine with out changing any of the steps in Eclipse indigo,java6,junit4.
    See this also : http://earlwillis.wordpress.com/2012/01/31/getting-started-with-junit-reports/

    ReplyDelete
  8. Hello, Anirban above quoted this page in my post: http://uaihebert.com/?p=63

    Nice material. [=

    ReplyDelete
  9. hi ,
    I am getting xml files instead of html !!...help me ....
    I followed the above mentioned steps

    ReplyDelete