Junit报告测试结果显示为空白

时间:2013-08-23 10:35:02

标签: eclipse ant selenium-webdriver junit4

每当我为第一个瞬间执行build.xml时,生成的报告都是空白的。现在当我再次执行第二次相同的build.xml时,它会显示上一次运行的时间戳。 任何人都可以帮助我理解这种情况

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="test">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="C:/Users/Downloads/eclipse"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="test.classpath">
    <pathelement location="bin"/>
    <pathelement location="../lib/junit-4.11.jar"/>
    <pathelement location="../lib/jxl-2.6.jar"/>
    <pathelement location="../lib/selenium-java-client-driver-1.0.2.jar"/>
    <pathelement location="../lib/selenium-server-standalone-2.31.0.jar"/>
    <pathelement location="../lib/xalan-2.7.1.jar"/>
    <pathelement location="C:/Users/Downloads/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant-junit.jar"/>
</path>
<target name="init">
    <mkdir dir="bin"/>
    <mkdir dir="build/classes" />
    <mkdir dir="dist"/>
</target>
<target name ="compile" depends="init">
<javac srcdir="src" destdir="build/classes"/>
</target>
<target name ="jar" depends="compile">
    <jar destfile="dist/test.jar" basedir="build/classes" />
</target>
<target name="clean">
    <delete dir="bin"/>
    <delete dir="dist" />
</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="bin" source="${source}" target="${target}" includeantruntime="false">
        <src path="src"/>
        <classpath refid="test.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="test">
    <mkdir dir="${junit.output.dir}"/>
    <junit fork="yes" printsummary="withOutAndErr">
        <formatter type="xml"/>
        <test name="AllTests" todir="${junit.output.dir}/Project"/>
        <classpath refid="test.classpath"/>
    </junit>
</target>
<target name="junitreport">
    <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}">
            <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${junit.output.dir}/Project"/>
    </junitreport>
</target>

1 个答案:

答案 0 :(得分:0)

听起来你的目标没有以所需的顺序运行。您确实应该在Ant任务本身中指定依赖项。例如,我在这个例子中添加了unitreport依赖于test的事实。

    <target name="test">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="xml"/>
            <test name="AllTests" todir="${junit.output.dir}/Project"/>
            <classpath refid="test.classpath"/>
        </junit>
    </target>
    <target name="junitreport" depends="test">
        <junitreport todir="${junit.output.dir}">
            <fileset dir="${junit.output.dir}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.output.dir}/Project"/>
        </junitreport>
    </target>
</project>