3

我正在尝试JUnit使用生成报告Ant。我创建了build.xml以下内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. --><project basedir="." default="build" name="myWebApp">
    <property environment="env"/>

    <property name="M2_REPO" value="C:/Users/samprity.kashyap/.m2/repository"/>
    <property name="ECLIPSE_HOME" value="C:/install/eclipse-jee-juno-win32/eclipse"/>
    <property name="junit.output.dir" value="junit"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>
    <path id="Apache Tomcat v7.0 [Apache Tomcat v7.0].libraryclasspath">
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/annotations-api.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/antlr-2.7.7.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-ant.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-ha.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina-tribes.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/catalina.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/commons-logging-1.1.1.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/dom4j-1.6.1.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/ecj-3.7.2.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/el-api.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/hibernate-commons-annotations-4.0.1.Final.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/hibernate-core-4.1.8.Final.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/jasper-el.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/jasper.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/javassist-3.15.0-GA.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/jboss-logging-3.1.0.GA.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/jsp-api.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/junit-4.8.2.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/mybatis-3.0.3.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/mysql-connector-java-5.1.12-bin.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.aop-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.asm-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.aspects-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.beans-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.context-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.context.support-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.core-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.expression-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.instrument-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.instrument.tomcat-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.jdbc-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.jms-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.orm-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.oxm-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.test-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.transaction-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.web-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.web.portlet-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.web.servlet-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/org.springframework.web.struts-3.1.2.RELEASE.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/servlet-api.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-api.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-coyote.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-dbcp.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-es.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-fr.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-i18n-ja.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-jdbc.jar"/>
        <pathelement location="../../../../Program Files/Apache Software Foundation/Tomcat 7.0/lib/tomcat-util.jar"/>
    </path>
    <path id="myWebApp.classpath">
        <pathelement location="target/classes"/>
        <pathelement location="${M2_REPO}/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar"/>
        <pathelement location="${M2_REPO}/junit/junit/4.5/junit-4.5.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-core/3.2.0.RELEASE/spring-core-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
        <pathelement location="${M2_REPO}/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-web/3.2.0.RELEASE/spring-web-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-context/3.2.0.RELEASE/spring-context-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-aop/3.2.0.RELEASE/spring-aop-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-beans/3.2.0.RELEASE/spring-beans-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-expression/3.2.0.RELEASE/spring-expression-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-webmvc/3.2.0.RELEASE/spring-webmvc-3.2.0.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/org/hibernate/hibernate/3.2.6.ga/hibernate-3.2.6.ga.jar"/>
        <pathelement location="${M2_REPO}/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar"/>
        <pathelement location="${M2_REPO}/commons-collections/commons-collections/2.1.1/commons-collections-2.1.1.jar"/>
        <pathelement location="${M2_REPO}/asm/asm-attrs/1.5.3/asm-attrs-1.5.3.jar"/>
        <pathelement location="${M2_REPO}/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
        <pathelement location="${M2_REPO}/antlr/antlr/2.7.6/antlr-2.7.6.jar"/>
        <pathelement location="${M2_REPO}/cglib/cglib/2.1_3/cglib-2.1_3.jar"/>
        <pathelement location="${M2_REPO}/asm/asm/1.5.3/asm-1.5.3.jar"/>
        <pathelement location="${M2_REPO}/org/hibernate/hibernate-annotations/3.3.1.GA/hibernate-annotations-3.3.1.GA.jar"/>
        <pathelement location="${M2_REPO}/org/hibernate/hibernate-commons-annotations/3.0.0.ga/hibernate-commons-annotations-3.0.0.ga.jar"/>
        <pathelement location="${M2_REPO}/org/hibernate/ejb3-persistence/1.0.1.GA/ejb3-persistence-1.0.1.GA.jar"/>
        <pathelement location="${M2_REPO}/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/flex/spring-flex-core/1.5.0.BUILD-SNAPSHOT/spring-flex-core-1.5.0.BUILD-SNAPSHOT.jar"/>
        <pathelement location="${M2_REPO}/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar"/>
        <pathelement location="${M2_REPO}/commons-codec/commons-codec/1.2/commons-codec-1.2.jar"/>
        <pathelement location="${M2_REPO}/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-context-support/3.0.5.RELEASE/spring-context-support-3.0.5.RELEASE.jar"/>
        <pathelement location="${M2_REPO}/com/adobe/blazeds/blazeds-core/4.0.0.14931/blazeds-core-4.0.0.14931.jar"/>
        <pathelement location="${M2_REPO}/com/adobe/blazeds/blazeds-common/4.0.0.14931/blazeds-common-4.0.0.14931.jar"/>
        <pathelement location="${M2_REPO}/com/adobe/blazeds/blazeds-proxy/4.0.0.14931/blazeds-proxy-4.0.0.14931.jar"/>
        <pathelement location="${M2_REPO}/com/adobe/blazeds/blazeds-remoting/4.0.0.14931/blazeds-remoting-4.0.0.14931.jar"/>
        <pathelement location="${M2_REPO}/org/springframework/spring-test/3.2.0.RELEASE/spring-test-3.2.0.RELEASE.jar"/>
        <path refid="Apache Tomcat v7.0 [Apache Tomcat v7.0].libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="target/classes"/>
        <copy includeemptydirs="false" todir="target/classes">
            <fileset dir="src/main/java">
                <include name="**/*.java"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="target/classes">
            <fileset dir="src/main/resources">
                <exclude name="**/*.java"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="target/classes"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" includeantruntime="false" source="${source}" target="${target}">
            <src path="src/main/java"/>
            <src path="src/main/resources"/>
            <include name="**/*.java"/>
            <exclude name="**/*.java"/>
            <classpath refid="myWebApp.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
    <target name="MapManagerTest">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="xml"/>
            <test name="com.sample.application.MapManagerTest" todir="${junit.output.dir}"/>
            <classpath refid="myWebApp.classpath"/>
        </junit>
    </target>

    <target name="MapManagerTest.testCheckUser">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="xml"/>
            <test name="com.sample.application.MapManagerTest" todir="${junit.output.dir}"/>
            <classpath refid="myWebApp.classpath"/>
        </junit>
    </target>
   <junitreport todir="./junit">
  <fileset dir="./junit">
    <include name="TEST-*.xml"/>
  </fileset>
  <report format="frames" todir="./junit/html"/>
</junitreport>

</project>

但是生成的报告没有显示任何价值。我创建了一个名为 junit 的文件夹,其中生成了 html 页面。overall-summary.html节目:

测试 失败 错误 成功率 时间
0 0 0 南 0.000

控制台输出:

Hibernate: 
    select
        user0_.id as id0_,
        user0_.password as password0_,
        user0_.username as username0_ 
    from
        USER user0_ 
    where
        user0_.username=?
Hibernate: 
    select
        userdetail0_.id as id1_0_,
        userdetail0_.firstname as firstname1_0_ 
    from
        USERDETAILS userdetail0_ 
    where
        userdetail0_.id=?
User [id=4, userName=xyz, password=abc]

和测试用例

@Test
public void testCheckUser() {                   
    User user=new User();
    user.setId(4);
    user.setUserName("xyz");
    user.setPassword("abc");
    UserDetails userDetails= new UserDetails();

    user.setUserDetails(userDetails);
    user1=mapManager.checkUser(user);
          equals(user1.equals(user));
}

这是运行时的控制台输出build.xml

Buildfile: D:\Users\samprity.kashyap\workspace\myWebApp\build.xml
build-subprojects:
init:
build-project:
     [echo] myWebApp: D:\Users\samprity.kashyap\workspace\myWebApp\build.xml
build:
junitreport:
[junitreport] Processing D:\Users\samprity.kashyap\workspace\myWebApp\junit\TESTS-TestSuites.xml to C:\Users\SAMPRI~1.KAS\AppData\Local\Temp\null1323106157
[junitreport] Loading stylesheet jar:file:/C:/install/eclipse-jee-juno-win32/eclipse/plugins/org.apache.ant_1.8.3.v20120321-1730/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 232ms
[junitreport] Deleting: C:\Users\SAMPRI~1.KAS\AppData\Local\Temp\null1323106157
build-subprojects:
init:
build-project:
     [echo] myWebApp: D:\Users\samprity.kashyap\workspace\myWebApp\build.xml
build-refprojects:
init-eclipse-compiler:
    [unzip] Expanding: C:\install\eclipse-jee-juno-win32\eclipse\plugins\org.eclipse.jdt.core_3.8.1.v20120531-0637.jar into C:\install\eclipse-jee-juno-win32\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib
    [unzip] Expanding: C:\install\eclipse-jee-juno-win32\eclipse\plugins\org.eclipse.jdt.core_3.8.2.v20120814-155456.jar into C:\install\eclipse-jee-juno-win32\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\lib
BUILD SUCCESSFUL
Total time: 2 seconds
4

0 回答 0