March 25, 2011

How to Create Reports using JUnit

Create Reports using JUnit:


After running test scripts in eclipse it would be good if we generate reports. Junit is one the most popular unit testing framework around. 


Below are the steps to generate reports:


1. Right click on project and click on "Export" option




   


2. Expand "General" node and select "Ant Buildfiles", click on "Next" button




3. Select the project (let all default options), 
Junit output Directory ... F:\Automation\First\junit  
click on "Finish" button




4. build.xml file should be created under project folder




5.  Now we need to add junit jar and Tools.jar file in Ant's "Global Entires"




6. Select "Window" menu, click on "Preferences"





7. In "Preferences" window, expand "Ant" root node, click on "Runtime"





8. Click on "Classpath" tab, expand "Global Entires" 





9. Click on "Add External JARs" button



10. Navigate to your "eclipse" directory (where eclipse is installed). Select "plugins ->org.junit_3.8.2.v3_8_2_v20100427-1100" directory. Select junit.jar file. and add Tools.jar which is located under java/JDK/Lib

11. Now right click on build.xml file and select Run As -> Ant Build.."





12. In "Edit Configuration and launch" window, select "build", "tootltip (the script we want to run)" and "junitreprot" checkboxes and click on "Run" button









13. All your test scripts will run and finally report will be generated under the same project directory under "junit" folder. To view JUint folder please refresh.




14. Click on "index.html", you will see the report 



Hope you all enjoy this post.





24 comments :

  1. I am gettind the below error after following ur step 11

    Please help me out!

    Buildfile: E:\Eclipse_workspace\testViewer\build.xml
    build-subprojects:
    init:
    build-project:
    [echo] testViewer: E:\Eclipse_workspace\testViewer\build.xml
    [javac] E:\Eclipse_workspace\testViewer\build.xml:42: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

    BUILD FAILED
    E:\Eclipse_workspace\testViewer\build.xml:42: Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK.
    It is currently set to "C:\Program Files\Java\jre6"

    Total time: 390 milliseconds

    ReplyDelete
  2. Hi Vijay,

    Itclearly showing that thare is some error in your Java_home :\Program Files\Java\jre6"

    U r Java_home shoudl point to :\Program Files\Java\JDK"

    please change u rJAVA_HOME PATH..

    if u have any problem pls send mail to nagaselenium@gmail.com

    Thanks,
    Naga

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi Naga,

    I am using Selenium RC with Junit and reporting the results as u have guided...

    I want to do two things:

    1. Assertion, on failing this step the test excution stops > This is possible using assert* commands

    2.Verfication, on pass/fail it has to be logged and test execution should continue further

    3. I want to take screenshots of failures...
    > Please let me know how can we do this

    Thanks,
    Vijay

    ReplyDelete
  6. Hi,

    I need the same behavior in TestNG. Is't possible to do,if yes please share it.

    ReplyDelete
  7. 12. In "Edit Configuration and launch" window, select "build", "tootltip (the script we want to run)" and "junitreprot" checkboxes and click on "Run" button

    tool tip and junitreport options are not available. Can you pls help me on this.

    And also when i run the script - > runas--java application

    ReplyDelete
  8. Hi Sruthi,

    Here tooltip means the script name.
    Send me your script so that i can help you..click contat me link there and send u r code..

    Thanks,
    Naga

    ReplyDelete
  9. Hi, I get error during execution:
    Buildfile: E:\eclipse\WebDriver\build.xml
    build-subprojects:
    init:
    build-project:
    [echo] WebDriver: E:\eclipse\WebDriver\build.xml
    [javac] E:\eclipse\WebDriver\build.xml:43: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    build:
    Sector:
    [mkdir] Created dir: E:\eclipse\WebDriver\junit
    [junit] Running Sector
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Test Sector FAILED
    junitreport:
    [junitreport] Processing E:\eclipse\WebDriver\junit\TESTS-TestSuites.xml to E:\DOCUME~1\CONSUL~1\LOCALS~1\Temp\null255203125
    [junitreport] Loading stylesheet jar:file:/E:/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 E:\eclipse\WebDriver\junit\TESTS-TestSuites.xml

    BUILD FAILED
    E:\eclipse\WebDriver\build.xml:135: Errors while applying transformations: Fatal error during transformation

    Total time: 4 seconds

    ReplyDelete
  10. i am following this procedure but index.html file is not generated...

    ReplyDelete
  11. Hi,
    I am following all steps finally i got the report,the report was generated in xml format.How to generate a report as a html format

    ReplyDelete
  12. getting this very same error as sum1 wrote above.. what to do now??
    BUILD FAILED
    E:\eclipse\WebDriver\build.xml:135: Errors while applying transformations: Fatal error during transformation

    ReplyDelete
  13. [junitreport] Processing D:\MonkeyTestingWS1\android-test\junit\TESTS-TestSuites.xml to C:\Users\MANISH~1.SIN\AppData\Local\Temp\null742538617
    [junitreport] Loading stylesheet jar:file:/D:/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 D:\MonkeyTestingWS1\android-test\junit\TESTS-TestSuites.xml

    ReplyDelete
  14. Hi, I get error during execution:
    Buildfile: E:\eclipse\WebDriver\build.xml
    build-subprojects:
    init:
    build-project:
    [echo] WebDriver: E:\eclipse\WebDriver\build.xml
    [javac] E:\eclipse\WebDriver\build.xml:43: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    build:
    Sector:
    [mkdir] Created dir: E:\eclipse\WebDriver\junit
    [junit] Running Sector
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Test Sector FAILED
    junitreport:
    [junitreport] Processing E:\eclipse\WebDriver\junit\TESTS-TestSuites.xml to E:\DOCUME~1\CONSUL~1\LOCALS~1\Temp\null255203125
    [junitreport] Loading stylesheet jar:file:/E:/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 E:\eclipse\WebDriver\junit\TESTS-TestSuites.xml

    BUILD FAILED
    E:\eclipse\WebDriver\build.xml:135: Errors while applying transformations: Fatal error during transformation

    Total time: 4 seconds

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  15. I'll right away grab your rss as I can not find your email subscription hyperlink or e-newsletter service. Do you'νe any?

    Please alloω me recognise in orԁеr that I may ѕubscribe.
    Thanks.

    Here іs my ѕite - pointsforfree.wordpress.com

    ReplyDelete
  16. Few comprehend the ramifications of site redesign on
    ranking. Press Release - You may ask your public
    relation company to write press release for you. Each google search has its own algorithms which can
    be rules that figure out how websites are placed
    in their search results rank.

    Here is my homepage ultimate demon review

    ReplyDelete
  17. A gold plated Swiss watch can market for over $4,000.
    A  Will this be a close look for everyday use or possibly for
    special occasions. As we've got outlined, seeking the perfect men's luxury watch can be described as a tricky and frequently
    times expensive proposition in the event you don't take the necessary steps.

    Also visit my weblog :: Watches-bestprice.com

    ReplyDelete
  18. I have tested this out and they are also excellent to prevent Acne killer
    recurrences. Along with asthma, camphor oil can be used freely on other parts of body.

    ReplyDelete
  19. A feature of the monster midweek gamble on Benitez to lose his job was the number of volunteers, it may
    have an how to get rid of acne ridden face.
    The three of us chuckled at Dillard's remark, and strolled out to the family of this child. A relaxed ecstatic state can remain a long time after the orgasm. Do this nightly for the best face moisturizer for how to get rid of acne prone skin. He gets a good laugh.

    ReplyDelete
  20. i have follow your step but index.html file not generated only xml file generated in junit folder so what to do for that

    ReplyDelete
  21. By Following U r Steps ,
    It creates Report in XML rather than HTML

    PLS provide steps to create report in HTML

    ReplyDelete
  22. Im getting this error java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0

    ReplyDelete