2

我有这个并且工作正常:

<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 中的路径元素将在单个测试中设置trunk/build/com,但在batchtest 中不会。

为了隐私,目录和包名称被混淆。

知道如何更改批处理测试以使类路径中的路径元素真正起作用吗?谢谢!

编辑:

这不起作用:

<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">。但是,当它启动时javajunit它不会从${build}类路径运行 junit。

编辑 3:

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

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

4

2 回答 2

3

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

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

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

于 2013-02-13T17:39:33.753 回答
0

如果您想从目录中获取批处理测试的${build}文件,您应该告诉

    <batchtest>
        <fileset dir="${build}/com/xyzcompany/abcproject/test/junit">
            <include name="**/*"/>
        </fileset>
    </batchtest>
于 2013-02-13T17:39:24.660 回答