2009-11-24 146 views
0

嘿,我一直在尝试获取ant文件来自动构建项目。该文件(附后)在我找到的网页上,并且非常详尽。Ant + Junit可以在第一次运行时再也不会再次运行

我的问题是,只要我不运行“干净”的目标,它就会工作。一旦我运行“干净”目标,“测试”目标停止工作。所有测试类都会出现NoClassFound错误。尽管它早些时候工作。

我正在使用最新版本的eclipse在Macbook(10.5.8)上工作。发生此错误使用Ant版本1.7.1

我修改的文件稍微以使其适应于被如下我的文件结构从蚀和从终端运行的文件:

src/ 
    packageA.packageB/ 
        ClassA.java 
        ... 
        ClassN.java 

unittests/ 
      packageA.packageB/ 
          AllClassTests.java 
          ClassATest.java 
          ... 
          ClassNTest.java 

lib/ 
    junit-4.7.jar 

蚂蚁文件是:

<project name="SampleJUnitTests" default="dist" basedir="."> 
<description> 
    DataTypes Build File 
</description> 
<!-- set global properties for this build --> 

<property name="project_name" value="DataTypes"/> 
<property name="src" location="src"/> 
<property name="build" location="bin"/> 
<property name="dist" location="dist"/> 
<property name="lib" location="lib"/> 
<property name="reports" location="reports"/> 
<property name="tests" location="unittests"/> 
<property name="tmp" location="tmp_file"/> 

<!-- the names of various distributable files --> 
<property name="jar_name" value="${project_name}.jar"/> 
<property name="war_name" value="${project_name}.war"/> 

<!-- top level targets --> 

<target name="compile" depends="init" description="compile the source code " > 
    <javac srcdir="${src}" destdir="${build}"> 
     <classpath> 
      <fileset dir="lib"> 
       <include name="**/*.jar"/> 
      </fileset> 
     </classpath> 
    </javac> 
</target> 

<target name="dist" depends="compile" description="generate the distributable files " > 
    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> 
    <jar jarfile="${dist}/${jar_name}" basedir="${build}"/> 
</target> 

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

<target name="run-tests" depends="compile" description="run your test suite" > 
    <junit printsummary="yes" haltonfailure="no" showoutput="yes" tempdir="${tmp}"> 
     <classpath> 
      <pathelement path="${build}"/> 
      <fileset dir="lib"> 
       <include name="**/*.jar"/> 
      </fileset> 
     </classpath> 
     <batchtest fork="yes" todir="${reports}/raw/"> 
     <formatter type="xml"/> 
     <fileset dir="${tests}"> 
      <include name="**/*.java"/> 
      <exclude name="**/All*Tests.java"/> 
     </fileset> 
     </batchtest> 
    </junit> 
</target> 

<target name ="test" depends="run-tests"> 
    <junitreport todir="${reports}"> 
     <fileset dir="${reports}/raw/"> 
     <include name="TEST-*.xml"/> 
     </fileset> 
     <report format="frames" todir="${reports}\html\"/> 
    </junitreport> 
</target> 

<target name ="run" depends="" description="if this project can be run, run it" > 
</target> 

<!-- supporting targets --> 

<target name="init" description="initialize the build environment" > 
    <!-- Create the time stamp --> 
    <tstamp/> 
    <!-- Create directory structures --> 
    <mkdir dir="${build}"/> 
    <mkdir dir="${lib}"/> 
    <mkdir dir="${dist}/lib"/> 
    <mkdir dir="${reports}"/> 
    <mkdir dir="${reports}/raw/"/> 
    <mkdir dir="${reports}/html/"/> 
    <mkdir dir="${tmp}"/> 
</target> 

<target name="all" depends="clean, test"> 
</target> 

我放弃了,并希望有人能对我的问题,照亮一盏灯。 非常感谢!

回答

2

你还没有任何构建测试类的Ant目标。如果您愿意,您可以将其作为compile目标的一部分:

<target name="compile" depends="init" description="compile the source code " > 
    <javac srcdir="${src}" destdir="${build}"> 
    <classpath> 
     <fileset dir="lib"> 
     <include name="**/*.jar"/> 
     </fileset> 
    </classpath> 
    </javac> 
    <javac srcdir="${tests}" destdir="${build}"> 
    <classpath> 
     <pathelement path="${build}"/> 
     <fileset dir="lib"> 
     <include name="**/*.jar"/> 
     </fileset> 
    </classpath> 
    </javac> 
</target> 
+0

谢谢!就是这样。我没有注意到,当我修改脚本时,他们的测试与源代码混合在一起。 :) – 2009-11-24 20:55:01