开发者

Ant+Junit works on first run and never again

开发者 https://www.devze.com 2022-12-12 16:12 出处:网络
Hey guys I\'ve been trying all day to get an ant file to automatically build my project. The file (appended below) was on a web page I found and is pretty thorough.

Hey guys I've been trying all day to get an ant file to automatically build my project. The file (appended below) was on a web page I found and is pretty thorough.

My problem is that it works as long as I don't run the "clean" target. Once the I run the "clean" target the "test" target ceases to work. I get NoClassFound errors on all test classes. Even though it worked earlier.

I'm working on a Macbook (10.5.8) using the latest version of eclipse. This error occurs running the file from eclipse and from a terminal using Ant version 1.7.1

I modified the file slightly to adapt it to my file structure which is as follows:

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

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

lib/
    junit-4.7.jar

The ant file is:

<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 开发者_JS百科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>

I give up and hope that someone can shine a light on my problem. Thanks a lot!


You haven't got any Ant target which builds the test classes. You could do this as part of the compile target if you wanted:

<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

精彩评论

暂无评论...
验证码 换一张
取 消