来自 ant 的空 Junit 报告 [英] Empty Junit reports from ant

查看:22
本文介绍了来自 ant 的空 Junit 报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ant 运行 junit 测试并生成报告.我能够成功运行测试,但报告文件为空.

I am trying to use ant to run junit tests and generate reports. I am able to successfully run the tests but the report files are empty.

我做错了什么?

这是我的 build.xml :

This is my build.xml :

<project name="JunitTest" default="test" basedir="."> 
    <property name="testdir" location="." /> 
    <property name="srcdir" location="." /> 
    <property name="full-compile" value="true" /> 
    <property name="test.reports" value="./reports" />

    <path id="classpath.base"/>
    <path id="classpath.test">

    <pathelement location="${testdir}" />
    <pathelement location="${srcdir}" />

    <path refid="classpath.base" />

    </path> 

    <target name="clean" >
        <delete verbose="${full-compile}"> 
            <fileset dir="${testdir}" includes="**/*.class" />
        </delete> `
    </target>

    <target name="compile" depends="clean">
        <javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}" >
            <classpath refid="classpath.test"/>
        </javac>
    </target>

    <target name="test" depends="compile">
        <junit>
            <classpath refid="classpath.test" />
            <formatter type="brief" usefile="false" />
            <test name="com.tests.nav1" />
        </junit>

        <junitreport todir="${test.reports}">
            <fileset dir="${test.reports}">
                <include name="TEST-*.xml" />
            </fileset>
            <report todir="${test.reports}" />
        </junitreport>
    </target>

</project>

这是控制台上的输出:

[junit] Using CLASSPATH C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src;C:\jars\junit.jar;C:\ant\lib\ant-launcher.jar;C:\ant\lib\ant.jar;C:\ant\lib\ant-junit.jar;C:\ant\lib\ant-junit4.jar 
[junit] Testsuite: com.tests.nav1 
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 48.187 sec 
[junit] ------------- Standard Output --------------- 
[junit] testnav2 
[junit] ------------- ---------------- --------------- 
[junitreport] Using class org.apache.tools.ant.taskdefs.optional.TraXLiaison 
[junitreport] Processing C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\reports\TESTS-TestSuites.xml to C:\Users\pmahajan\AppData\Local\Temp\null236099757 
[junitreport] Loading stylesheet jar:file:/C:/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl 
[junitreport] Transform time: 330ms 
[junitreport] Deleting: C:\Users\pmahajan\AppData\Local\Temp\null236099757 

BUILD SUCCESSFUL
Total time: 49 seconds

推荐答案

如果你看一下 ant 片段,有几个问题:

If you look at the ant snippet, there are a few issues:

  • 您已经设置了usefile=false,这意味着没有创建输出文件
  • 您已经设置了formatter type=brief,它将只打印失败测试的详细信息
  • 您还需要指定 todir - <test> 标记中报告必须进入的文件夹 - 默认为当前文件夹.这应该与您在 任务中使用的文件夹相匹配.
  • You have set usefile=false, which means no output file is created
  • You have set formatter type=brief, which will print detailed information only for failed tests
  • You need to also specify the todir - the folder where the report has to go in the <test> tag - the default is current folder. This should match the folder you are using in <junitreport> task.

您可以尝试使用以下更新的 部分...

You can try with the following updated <junit> section...

    <junit>
        <classpath refid="classpath.test" />
        <formatter type="xml"/>
        <test name="com.tests.nav1" todir="${test.reports}"/>
    </junit>

这篇关于来自 ant 的空 Junit 报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆