从蚂蚁的Junit空报告 [英] Empty Junit reports from ant
本文介绍了从蚂蚁的Junit空报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用Ant运行JUnit测试并生成报告。
我能够成功地运行测试,但该报告文件是空的。
我是什么做错了吗?
这是我的build.xml:
<,项目名称=JunitTest默认为测试BASEDIR =>
<属性名=TESTDIR位置=。 />
<属性名=SRCDIR位置=。 />
<属性名=全编译VALUE =真/>
<属性名=test.reportsVALUE =./报告/> <路径ID =classpath.base/>
&所述;路径ID =classpath.test> < pathelement位置=$ {} TESTDIR/>
< pathelement位置=$ {SRCDIR}/> <路径REFID =classpath.base/> < /路径> <目标名称=干净>
<删除冗长=$ {全编译}>
<文件集DIR =$ {} TESTDIR包括=** / *类。/>
< /删除> `
< /目标与GT; <目标名称=编译取决于=干净>
< javac的SRCDIR =$ {SRCDIR}DESTDIR =$ {} TESTDIR冗长=$ {全编译}>
<类路径REFID =classpath.test/>
< / javac的>
< /目标与GT; <目标名称=测试依赖=编译>
<&JUnit的GT;
<类路径REFID =classpath.test/>
<格式化类型=简单usefile =FALSE/>
<试验NAME =com.tests.nav1/>
< / JUnit的> < junitreport todir =$ {} test.reports>
<文件集DIR =$ {} test.reports>
<包括姓名=TEST - * XML。/>
< /文件集>
<报告todir =$ {} test.reports/>
< / junitreport>
< /目标与GT;< /项目>
和这是在控制台上的输出:
[JUnit的]使用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的]测试工具:com.tests.nav1
[JUnit的]测试运行:2,失败:0,错误:0,经过时间:48.187秒
[JUnit的] -------------标准输出---------------
[JUnit的] testnav2
[JUnit的] ------------- ---------------- ---------------
[junitreport]使用类org.apache.tools.ant.taskdefs.optional.TraXLiaison
[junitreport]处理C:\\eclipse\\eclipse-java-helios-SR1-win32\\eclipse\\JunitWS\\SeleniumTraining\\src\\reports\\TESTS-TestSuites.xml到C:\\用户\\ pmahajan \\应用程序数据\\本地的\\ Temp \\ null236099757
[junitreport]加载样式表jar:file:/C:/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport]转换时间:330ms
[junitreport]删除C:\\用户\\ pmahajan \\应用程序数据\\本地的\\ Temp \\ null236099757BUILD SUCCESSFUL
总时间:49秒
解决方案
如果你看看蚂蚁片段中,有几个问题:
- 您已设置
usefile = FALSE
,这意味着没有输出文件被创建 - 您已设置
格式
键入=简短
,这将显示详细的信息仅用于测试失败 - 您还需要指定
todir
- 在该报告已在&LT进入该文件夹;试验>
标签 - 默认为当前文件夹。这应该与您正在使用的文件夹< junitreport方式>
任务
您可以尝试以下方法更新<&JUnit的GT;
部分...
<&JUnit的GT;
<类路径REFID =classpath.test/>
<格式化类型=XML/>
<试验NAME =com.tests.nav1todir =$ {} test.reports/>
< / 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.
What am I doing wrong ?
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>
and this is the output on the console :
[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
解决方案
If you look at the ant snippet, there are a few issues:
- 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>
这篇关于从蚂蚁的Junit空报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文