Ant - 设置ClassPath不适用于批处理测试

时间:2013-02-13 17:29:31

标签: 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

如您所见,classpath中的pathelement会在单个测试中设置trunk / build / com,但不会在batchtest中设置。

目录和包名称为隐私进行了模糊处理。

知道如何更改批处理测试,以便类路径中的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">确实有意义。但是,当它为java旋转junit时,它不会从${build}类路径运行junit。

编辑3:

<batchtest>
    <fileset dir="${build}">
        <include name="com/xyzcopmany/abcproject/test/junit/*"/>
    </fileset>
</batchtest>

最终答案。 Ant应该有更好的文档。这是一个复杂的产品......

2 个答案:

答案 0 :(得分:3)

设置

<fileset dir="com/xyzcompany/abcproject/test/junit">

<batchtest>
    <fileset dir="${buildTests}">
        <include name="**/*Test*.class"/>
    </fileset>
</batchtest>

不要在$ {buildTests}中包含com / xyzcompany / abcproject / test / junit部分。

答案 1 :(得分:0)

如果您想从${build}目录中获取批量测试的文件,您应该这样说

    <batchtest>
        <fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
            <include name="**/*"/>
        </fileset>
    </batchtest>