I am writing a web application which should be tested with JUnit framework. So please suggest me how we can use JUnit in Jsp and servlet and also how to generate test case reports using Ant?? Thanks in advance

Why cant we use Cactus? I have heard about that and what it differs from other test cases?

+4  A: 

For servlets I use the spring framework mock classes - there are mock request, response, servlet context, etc. You do not need to use the spring framework in your application to use them.

Regarding your second question, i think what you are looking for is the junitreport ant task. Here is a sample (taken from here):

<target name="junit" description="Runs the unit tests" depends="jar">
    <delete dir="${junit.out.dir.xml}"/>
    <mkdir  dir="${junit.out.dir.xml}"/>
    <junit printsummary="yes" haltonfailure="no">
        <classpath refid="classpath.test"/>
        <formatter type="xml"/>
        <batchtest fork="yes" todir="${junit.out.dir.xml}">
            <fileset dir="${src.dir}" includes="**/*Test.java"/>

<target name="junitreport" description="Create a report for the rest result">
    <mkdir dir="${junit.out.dir.html}"/>
    <junitreport todir="${junit.out.dir.html}">
        <fileset dir="${junit.out.dir.xml}">
            <include name="*.xml"/>
        <report format="frames" todir="${junit.out.dir.html}"/>
David Rabinowitz
+1  A: 

Yes, cactus is an good option.. it is mainly for Integration testing and can also satisfy the Unit testing. For details u just try this site http://jakarta.apache.org/cactus