我有这个并且工作正常:
<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
如您所见,类路径中的路径元素会在单个测试中设置 trunk/build/com,但在批量测试中不会设置。
出于隐私考虑,对目录和包名称进行了混淆。
知道如何更改批测试以使类路径中的路径元素真正起作用吗?谢谢!
编辑:
这不起作用:
<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">
没有任何意义,因为类(class)不知道它正在构建中。因此,设置类路径是正确的选项,但不适用于 <batchtest>
.
编辑2:
现在我仔细想想,这样做确实有意义<fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
。然而,当它旋转起来时java
对于 junit
它不从${build}
运行junit类路径。
编辑3:
<batchtest>
<fileset dir="${build}">
<include name="com/xyzcopmany/abcproject/test/junit/*"/>
</fileset>
</batchtest>
最终答案。 Ant 确实应该有更好的文档。这是一个复杂的产品...
最佳答案
设置
<fileset dir="com/xyzcompany/abcproject/test/junit">
到
<batchtest>
<fileset dir="${buildTests}">
<include name="**/*Test*.class"/>
</fileset>
</batchtest>
不要在 ${buildTests} 中包含 com/xyzcompany/abcproject/test/junit 部分。
关于java - Ant - 设置 ClassPath 对于批量测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14859391/