【发布时间】:2011-05-20 23:46:35
【问题描述】:
我有一个运行 JUnits 测试的 ant 文件。这些测试依赖于某些配置文件的相对路径。我尝试设置批处理测试的工作目录,但失败了。
我希望工作目录为${plugins.dir}/${name}
ant 脚本的 JUnit 部分:
<junit haltonfailure="no" printsummary="on" fork="true" showoutput="true" dir="${plugins.dir}/${name}">
<jvmarg value="-Duser.dir=${plugins.dir}/${name}"/>
<classpath>
<path refid="project.classpath"/>
<pathelement location="${plugins.dir}/${dependency}/@dot/"/>
<pathelement location="${plugins.dir}/${name}/" />
</classpath>
<formatter type="xml" />
<sysproperty key="basedir" value="${plugins.dir}/${name}"/>
<sysproperty key="dir" value="${plugins.dir}/${name}"/>
<batchtest todir="${junit.output}">
<fileset dir="${dir}">
<include name="**\*AllTests.class" />
</fileset>
</batchtest>
</junit>
我用谷歌搜索过,但我发现的解决方法是设置“dir”、“sysproperty”或“jvmarg”。如您所见,我已经尝试了所有方法:)
有没有办法打印标签中的当前目录?它不支持。这将允许我验证目录是否实际更改以及更改为什么。
这个等式中的一个通配符是它在 Hudson 中运行,它启动了一个启动 antrunner 的 eclipse 进程。这样我们就可以同时运行 junit 和 eclipse 插件 junit 测试。应该与我认为的问题无关。
【问题讨论】:
-
不可能简单地修复您的测试以使其独立吗?例如。如果您需要的资源放在类路径中的某个位置,则可以改为通过
getClass().getResource(String)加载它们。 -
@Mark peters,是的,这是可能的。但这涉及更新大约 400-500 个测试,所以我更愿意考虑 B 计划。