java - Ant - 设置 ClassPath 对于批量测试不起作用

标签 java ant junit

我有这个并且工作正常:

<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/

相关文章:

java - 获取一个 JScrollPane 的所有内容

java - 如何在Spring WebClient中设置和处理超时?

java - Ant 中的"Error running javac compiler"

java - 使用 ant 调试我的 Web 应用程序

java - JMockit : How to inject a MockUp class into a tested class?

java - Gradle 下的 JUnit 5 具有多个源集

java - IntelliJ 将包和导入放在文件头下方

java - Libgdx BitmapFont NullPointerException

java - Ant unless 属性不起作用?

Gradle依赖 json-simple 错误