gpt4 book ai didi

ant - 来自 ant 的空 Junit 报告

转载 作者:行者123 更新时间:2023-12-04 09:57:40 25 4
gpt4 key购买 nike

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

我究竟做错了什么 ?

这是我的 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 代码段,会发现一些问题:

  • 您已设置 usefile=false ,这意味着没有创建输出文件
  • 您已设置 formatter type=brief , 将仅打印失败测试的详细信息
  • 您还需要指定 todir - 报告必须放在 <test> 中的文件夹标签 - 默认为当前文件夹。这应该与您在 <junitreport> 中使用的文件夹相匹配任务。

  • 您可以尝试使用以下更新的 <junit>部分...
        <junit>
    <classpath refid="classpath.test" />
    <formatter type="xml"/>
    <test name="com.tests.nav1" todir="${test.reports}"/>
    </junit>

    关于ant - 来自 ant 的空 Junit 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352353/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com