Ant和Junit所有测试都失败了

时间:2012-12-04 20:01:21

标签: java ant junit

我需要使用ant来测试我在Java中开发的项目。我不能让蚂蚁正常工作。我还没理解如何设置ant的路径,以便正确测试项目所需的文件。

期待哪种类型的文件?来源还是二元?

我正在使用此ant文件来运行测试:

<project name="acmetelecom" default="compile">

<property name="src" location="src/acme/com/acmetelecom" />
<property name="src" location="src/acme/com/acmetelecom" />
<property name="fit" location="fit" />
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="report" location="report" />
<property name="junit.report" location="report/junit" />
<property name="fit.report" location="report/fit" />
<path id="lib.classpath">
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    <include name="*" />
    </fileset>
</path>
<path id="test.classpath">
    <path refid="lib.classpath" />
<pathelement location="lib/junit/junit-4.4.jar" />
    <pathelement location="lib/junit/junit-4.4-src.jar" />
    <pathelement location="${bin}" />
</path>

<target name="compile">
    <mkdir dir="${bin}" />
    <javac srcdir="${src}" destdir="${bin}">
        <classpath refid="lib.classpath" />
    </javac>
</target>


<target name="junit" depends="compile">
    <mkdir dir="${junit.report}" />
    <junit printsummary="yes" fork="yes" haltonfailure="no">
        <classpath refid="test.classpath" />
        <formatter type="plain" />
        <batchtest fork="yes" todir="${junit.report}">
            <fileset dir="bin/com/acmetelecom">
                <include name="**/*Test.class" />
            </fileset>
        </batchtest>
    </junit>
</target>
<target name="fit" depends="compile">
    <mkdir dir="${fit.report}" />
    <java classname="fitlibrary.runner.FolderRunner" fork="yes"
            failonerror="yes">
        <classpath refid="test.classpath" />
        <arg value="${fit}" />
        <arg value="${fit.report}" />
    </java>
    <echo>Please see the FIT report page for more details</echo>
</target>
<target name="clean">
    <delete dir="${bin}" />
    <delete dir="${report}" />
</target>
</project>

我看不出我做错了什么!测试与源代码位于同一目录中。

2 个答案:

答案 0 :(得分:1)

Ant脚本的根节点是project标记。一个example我建议开始简单...比如让你的Java源代码编译,然后添加junit等。

答案 1 :(得分:0)

您正在将.class文件写入$ {bin}。尝试将其作为batchtest文件集中的参数。无论如何都不需要提供封装目录路径。 * / .class将检查所有目录。

  <batchtest fork="yes" todir="${junit.report}">
        <fileset dir="${bin}">
            <include name="**/*Test.class" />
        </fileset>
    </batchtest>
相关问题