【问题标题】:Ant - Setting ClassPath Does Not Work For Batch TestAnt - 设置 ClassPath 不适用于批量测试
【发布时间】: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

将其设置为&lt;fileset dir="${build}/com/xyzcompany/abcproject/test/junit"&gt; 没有任何意义,因为该类不知道它正在构建中。因此,设置类路径是正确的选项,但不适用于&lt;batchtest&gt;

编辑 2:

现在我仔细想想,&lt;fileset dir="${build}/com/xyzcompany/abcproject/test/junit"&gt; 确实有意义。但是,当它为junit 启动java 时,它不会从${build} 类路径运行junit。

编辑 3:

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

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

【问题讨论】:

    标签: java ant junit


    【解决方案1】:

    设置

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

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

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

    【讨论】:

    • 好的,我认为你不应该包含 com/xyzcompany/abcproject/test/junit 部分。只需将您的测试编译到某个目录并包含该目录的路径
    • 谢谢,你是最接近帮助我的人。想要确切答案的人,请参阅我的最后编辑。
    • 能否请您混淆您的评论(公司名称和项目名称)或删除它?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 2012-07-05
      • 2014-09-15
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多