Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JUnit AntClassNotFoundException_Java_Ant_Junit - Fatal编程技术网

Java JUnit AntClassNotFoundException

Java JUnit AntClassNotFoundException,java,ant,junit,Java,Ant,Junit,运行“ant测试”目标时,我得到ClassNotFoundException。 所有路径和库都存在,包括位于lib文件夹中的junit-4.8.1.jar <project name="progs" default="test" basedir="."> <!--++++++++++ Properties ++++++++++--> <property name="src-main" location="PC_Serie_3"/> <pro

运行“ant测试”目标时,我得到ClassNotFoundException。 所有路径和库都存在,包括位于lib文件夹中的junit-4.8.1.jar

<project name="progs" default="test" basedir=".">

  <!--++++++++++ Properties ++++++++++-->
  <property name="src-main" location="PC_Serie_3"/>
  <property name="src-test" location="PC_Serie_3_Tests"/>
  <property name="target"  location="target"/>
  <property name="target-classes"  location="target/PC_Serie_3"/>
  <property name="target-test-classes"  location="target/PC_Serie_3_Tests"/>
  <property name="target-test-reports"  location="target/test-reports"/>

  <path id="test.extlibs.class.path">
    <fileset dir="lib">
      <include name="**/*.jar" />
    </fileset>
  </path>

  <!--++++++++++ Targets ++++++++++-->
  <target name="init" description ="Creates the target folders">
    <mkdir dir="${target-classes}"/>
    <mkdir dir="${target-test-classes}"/>
    <mkdir dir="${target-test-reports}"/>
  </target>

  <target name="clean" description="Removes the target folders" >
    <delete includeEmptyDirs="true" failonerror="false" verbose="true" >
        <fileset dir="${target}" defaultexcludes="false"/>
    </delete>
  </target>

  <target name="compile-main" depends="init" description="Compiles the main source" >
    <javac debug="true"
           srcdir="${src-main}"
           destdir="${target-classes}"
           includeantruntime="false">
    </javac>
  </target>

  <target name="compile-test" depends="compile-main" description="Compiles the test source" >
    <javac  debug="true"
            debugLevel="source"
            srcdir="${src-test}"
            destdir="${target-test-classes}"
            includeantruntime="true">
      <classpath>
        <pathelement location="${target-classes}"/>
        <path refid="test.extlibs.class.path" />
      </classpath>
    </javac>
  </target>

<target name="test" depends="compile-test" description="Runs the tests">
    <echo>Running the junit tests...</echo>
    <junit printsummary="yes" haltonfailure="true" showoutput="true" >
      <classpath>
        <pathelement location="${src-main}"/>
        <pathelement location="${target-classes}"/>
        <pathelement location="${target-test-classes}"/>
        <path refid="test.extlibs.class.path" />
      </classpath>

    <batchtest fork="yes" todir="${target-test-reports}" >
        <fileset dir="${src-test}">
          <include name="**/*Test*.java"/>
        </fileset>
        <formatter type="xml"/>
        <formatter type="plain" usefile="false" />
      </batchtest>
      </junit>
  </target>

  <target name="package" depends="test" description="Packages the main classes into a jar" >
    <buildnumber />
    <jar jarfile="${target}/library.jar" basedir="${target-classes}"/>
  </target>

    <!-- USAGE: ant deploy-app -->
    <target name="deploy-lib" depends="package">
    </target>
</project>

我认为问题在于您将junit指向源文件,而不是编译的类文件。另外,
文件集
应该包括
*Test*.java
时,它包括
*Test*.class

尝试用以下内容替换batchtest元素:

<batchtest fork="yes" todir="${target-test-reports}" >
    <fileset dir="${target-test-classes}">
        <include name="**/*Test*.class"/>
    </fileset>
    <formatter type="xml"/>
    <formatter type="plain" usefile="false" />
</batchtest>

我已尝试使用fork=“否”,但问题仍然存在。你是对的。谢谢你的帮助,这让我一整天都很生气!
<batchtest fork="yes" todir="${target-test-reports}" >
    <fileset dir="${target-test-classes}">
        <include name="**/*Test*.class"/>
    </fileset>
    <formatter type="xml"/>
    <formatter type="plain" usefile="false" />
</batchtest>