新手区 [求助] junit 测试报告显示的是上一次的测试结果,求解惑

紫电清风 · 2016年06月22日 · 最后由 胡刚 回复于 2016年06月23日 · 1760 次阅读

使用 ANT+Appium+Junit 进行测试,之后生成的 junit 测试报告显示的总是上一次的测试结果。
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="pearVideo_Demo">
    <property environment="env"/>
    <property name="junit.output.dir" value="junit"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.8"/>
    <property name="source" value="1.8"/>
    <path id="pearVideo_Demo.classpath">
        <pathelement location="bin"/>
        <pathelement location="../../导入包/java-client-1.6.0.jar"/>
        <pathelement location="../../导入包/selenium-java-2.44.0.zip"/>
        <pathelement location="../../导入包/selenium-server-standalone-2.44.0.jar"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </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" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="pearVideo_Demo.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="Android_0603">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="xml"/>
            <test name="pearVideo_Demo_Android.Android_0603" todir="${junit.output.dir}"/>
            <classpath refid="pearVideo_Demo.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}"/>
        </junitreport>
    </target>
</project>

但是我的 junit 文件夹会生成两个.xml 文件,如下:

每次测试数据会保存在第一个文件里,但是生成的测试报告拿的是第二个文件的数据(进行测试的时候,第二个文件会继承第一个文件的数据)所以每次生成的报告都会是上一次的测试结果。能不能帮忙看看,谢谢!
我尝试修改成

</target>
<target name="junitreport">
    <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}">
            <include name="TESTS-*.xml"/>
        </fileset>
        <report format="frames" todir="${junit.output.dir}"/>
    </junitreport>
</target>

提示:

[junitreport] the file D:\Java_test\pearVideo_Demo\junit\TESTS-TestSuites.xml is not a valid testsuite XML document

junit 测试报告里面显示 0.....

共收到 3 条回复 时间 点赞

${junit.output.dir}新建个子目录,比如以当前执行的时间为目录名 ${time}, 可以在初始化的时候定义 ;
Junit 标签下相应修改成:





Junitreport 标签下相应修改成:






#1 楼 @neven7
我按照你说的该成下面这样:

<?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="pearVideo_Demo">
    <property environment="env"/>
    <property name="junit.output.dir" value="junit"/>
    <property name="time" value="${NOW}" />
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.8"/>
    <property name="source" value="1.8"/>
    <path id="pearVideo_Demo.classpath">
        <pathelement location="bin"/>
        <pathelement location="../../导入包/java-client-1.6.0.jar"/>
        <pathelement location="../../导入包/selenium-java-2.44.0.zip"/>
        <pathelement location="../../导入包/selenium-server-standalone-2.44.0.jar"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </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" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="pearVideo_Demo.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="Android_0603">
        <mkdir dir="${junit.output.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr">
            <batchtest todir="${junit.output.dir}/${time}">
            <fileset dir="${build.dest}">
            <include name="**/*TestSuite.class" />
            </fileset>
            </batchtest>
            <formatter type="xml"/>
            <test name="pearVideo_Demo_Android.Android_0603" todir="${junit.output.dir}/${time}"/>
            <classpath refid="pearVideo_Demo.classpath"/>
        </junit>
    </target>
    <target name="junitreport">
        <junitreport todir="${junit.output.dir}">
        <fileset dir="${junit.output.dir}/${time}">
        <include name="TEST-*.xml" />
        </fileset>
        <report format="noframes" todir="${{junit.output.dir}}/${time}" />
        </junitreport>
    </target>
</project>

跑出后报告内容显示为 0 ,


新创建的 ${NOW}文件中也有本次测试的数据,不知道为什么报告里面显示 0 。
junit-noframes.html 和 index.xml 都没有测试结果,帮忙再看下,是不是我写错什么了,谢谢!

中{build.dest}是你 test class 编译后的.class 目录; 中 **/*TestSuite 是你测试的 suite 测试类

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册