簡體   English   中英

帶有Ant的JUnit,另一個java.lang.ClassNotFoundException

[英]JUnit with Ant, another java.lang.ClassNotFoundException

第一次接觸Ant,真的不知道我在做什么。 我的猜測是我沒有正確設置JUnit類路徑。 我看到有很多與此問題類似的問題,盡管沒有任何建議對我有用。 請幫忙!

我的項目目錄結構:(我懷疑我的目錄結構被嚴重搞亂了)

MyProject/
    bin/main/
        project.class
        test1.class
        test2.class
        test3.class
    build/main/project
        Project.class
    build/test/main
        test1.class
        test2.class
        test3.class
    build/test/project
        test1.class
        test2.class
        test3.class
    lib/
        junit-4.11.jar
        hamcrest-all-1.3.jar
    src/main/java/
        project.java
    src/test/java/
        test1.java
        test2.java
        test3.java
    build.xml

我的build.xml

<project name="junit-example">
  <property name="main.build.dir" value="build/main"/>
  <property name="main.src.dir" value="src/main/java"/>
  <property name="test.build.dir" value="build/test"/>
  <property name="test.src.dir" value="src/test/java"/>

  <path id="classpath.test">
    <pathelement location="lib/junit-4.11.jar"/>
    <pathelement location="lib/hamcrest-core-1.3.jar"/>
    <pathelement location="${main.build.dir}"/>
  </path>

  <target name="compile">
    <mkdir dir="${main.build.dir}"/>
    <javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false"/>
  </target>

  <target name="test-compile" depends="compile">
    <mkdir dir="${test.build.dir}"/>
    <javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
        <classpath refid="classpath.test"/>
    </javac>
  </target>

  <target name="testAll" depends="test-compile">
    <junit printsummary="on" haltonfailure="yes" fork="no">
        <classpath>
          <path refid="classpath.test"/>
          <pathelement location="${test.build.dir}"/>
        </classpath>
        <formatter type="brief" usefile="false" />
        <batchtest>
            <fileset dir="${test.src.dir}" includes="**/*Test.java" />
        </batchtest>
    </junit>
  </target>
</project>

您將batchtest定義為

<batchtest>
    <fileset dir="${test.src.dir}" includes="**/*Test.java" />
</batchtest>

但是,您在${test.src.dir}中的文件是

src/test/java/
    test1.java
    test2.java
    test3.java

嘗試將batchtest更改為

<batchtest>
    <fileset dir="${test.src.dir}" includes="**/*test?.java" />
</batchtest>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM