【发布时间】:2013-01-29 08:15:02
【问题描述】:
我有这个并且工作正常:
<target name="runjunit">
<junit>
<classpath>
<pathelement path="${build}"/>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</classpath>
<test name="com.xyzcompany.abcproject.test.junit.CalculatorTest"/>
<formatter type="brief" usefile="false"/>
</junit>
</target>
但是,我有多个测试。所以我这样做:
<target name="runjunit">
<junit>
<classpath>
<pathelement path="${build}"/> <---- this doesn't seem to work anymore
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</classpath>
<batchtest>
<fileset dir="com/xyzcompany/abcproject/test/junit">
<include name="**/*.*"/>
</fileset>
</batchtest>
<formatter type="brief" usefile="false"/>
</junit>
</target>
但是,这告诉我该目录不存在:
C:\Users\me\Desktop\repository\mainproj\trunk\com\xyzcompany\abcproject\test\junit does not exist.
以上应该是:
C:\Users\me\Desktop\repository\mainproj\trunk\build\com\xyzcompany\abcproject\test\junit
如您所见,classpath 中的 path 元素会在单次测试中设置 trunk/build/com,但在批处理测试中不会。
为了隐私而混淆的目录和包名称。
知道如何更改批处理测试以使类路径中的 pathelement 真正起作用吗?谢谢!
编辑:
这不起作用:
<batchtest>
<fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
<include name="**/*.*" />
</fileset>
</batchtest>
它给了我:
java.lang.ClassNotFoundException: CalculatorTest
将其设置为<fileset dir="${build}/com/xyzcompany/abcproject/test/junit"> 没有任何意义,因为该类不知道它正在构建中。因此,设置类路径是正确的选项,但不适用于<batchtest>。
编辑 2:
现在我仔细想想,<fileset dir="${build}/com/xyzcompany/abcproject/test/junit"> 确实有意义。但是,当它为junit 启动java 时,它不会从${build} 类路径运行junit。
编辑 3:
<batchtest>
<fileset dir="${build}">
<include name="com/xyzcopmany/abcproject/test/junit/*"/>
</fileset>
</batchtest>
最终答案。 Ant 确实应该有更好的文档。这是一个复杂的产品...
【问题讨论】: