JUnit通过Ant执行失败

JUnit通过Ant执行失败,ant,junit,Ant,Junit,在执行简单的junit测试类时,我不断得到java.lang.ClassNotFoundException。 4.我就是找不到问题所在。。 这是我的文件系统。主应用程序运行良好。 这是我的ant文件: <project name="MyProject" default="dist" basedir="."> <description> controller build </description> <!-- set gl

在执行简单的junit测试类时,我不断得到java.lang.ClassNotFoundException。 4.我就是找不到问题所在。。 这是我的文件系统。主应用程序运行良好。 这是我的ant文件:

<project name="MyProject" default="dist" basedir=".">
    <description>
       controller build
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <property name="TALK" value="true" />


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


  <path id="test.classpath">
    <pathelement location="${build}" />
    <pathelement location="..\lib\junit\junit.jar" />
      <fileset dir="..\lib">
        <include name="**/*.jar"/>
      </fileset>
  </path>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" verbose="${TALK}">
        <classpath refid="class.path" />
    </javac>    
  </target>

  <target name="dist" depends="compile,test"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/controller.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>

  <target name="test" depends="compile">
    <junit printsummary="yes" showoutput="true">
      <classpath refid="test.classpath"/>      
      <formatter type="brief" usefile="false" />
      <test name="workflowShouldHaveValidXML" />
      <!--test name="environmentHasValidXml" /-->
      <!--test name="workflowHasValidXml" /-->
    </junit>
  </target>


</project>
这是我的目录结构:

svn\trunk\controller\build_controller.xml    \\ Ant file
svn\trunk\controller\src\com\controller\core\*.java  \\ main app sources
svn\trunk\controller\dist\lib\controller.jar  \\ the main product 
svn\trunk\controller\build\com\controller\core\*.class   \\the main product *.class
svn\trunk\controller\test\com\controller\core\workflowShouldHaveValidXML.java  \\ the test case class
svn\trunk\lib\junit\junit.jar 
svn\trunk\lib\java\*.jar   \\ third party jars

您需要使用完全限定的类名(包括包),而不仅仅是简单的类名:

在junit任务中,请尝试:

<test name="com.controller.core.workflowShouldHaveValidXML" />


src的位置在哪里?我在构建脚本中看到src被设置为src,但在svn列表中没有src文件夹。很抱歉,时间太晚了,我解决了这个问题:svn\trunk\controller\src\com\controller\core\
<test name="com.controller.core.workflowShouldHaveValidXML" />