Problemer med JUnit test i ANT
Jeg har følgende build-fil til ant:<?xml version="1.0"?>
<project default="all" name="My first standard buildfile" basedir=".">
<!-- description of build.xml -->
<description>
build file placed in ${env.HOME}/${packagepath}
</description>
<!-- properties ******************************************************** -->
<!-- set package properties for this build: these are varied per package -->
<property name="package" value="firstAnt"/>
<property name="packagepath" value="d:\firstAnt"/>
<!-- set global properties for this build - these are universal -->
<property environment="env"/>
<property name="home" value="${env.HOME}"/>
<property name="homedir" value="."/>
<property name="classpath" value="${env.CLASSPATH}"/>
<property name="src" location="${packagepath}/src"/>
<property name="reports" location="${packagepath}/reports"/>
<property name="dist" location="${packagepath}/dist"/>
<property name="docs" location="${packagepath}/docs"/>
<property name="unit" location="${packagepath}/unit"/>
<property name="backup" location="backup"/>
<property name="classes" location="${packagepath}/classes"/>
<!-- properties ******************************************************** -->
<!-- Create the output directories -->
<target name="create.dirs">
<echo message="creating directories if they don't exist"/>
<mkdir dir="${packagepath}" />
<mkdir dir="${src}" />
<mkdir dir="${reports}" />
<mkdir dir="${dist}" />
<mkdir dir="${docs}" />
<mkdir dir="${unit}" />
<mkdir dir="${backup}" />
<mkdir dir="${classes}" />
</target>
<!-- move the ${homedir}/*.java to ${src} directory tree -->
<target name="init.src" description="move source to ${src}"
depends="create.dirs">
<echo message="moving *.java to ${src}"/>
<copy todir="${backup}">
<fileset dir="${homedir}">
<include name="*.java" />
</fileset>
</copy>
<move todir="${src}">
<fileset dir="${homedir}">
<include name="*.java" />
<exclude name="*Test.java" />
</fileset>
</move>
<move todir="${unit}">
<fileset dir="${homedir}">
<include name="*.java" />
</fileset>
</move>
</target>
<!-- compile source -->
<target name="compile" description="compiles *.java files in ${src} to ${classes}"
depends="init.src">
<echo message="compiling ${src}/*.java to ${prog}/" />
<javac srcdir="${src}"
destdir="${classes}" />
</target>
<!-- compile unit tests -->
<target name="compile.unit" description="compiles *Test.java files in ${unit}" depends="init.src">
<echo message="compiling ${src}/*Test.java" />
<javac srcdir="${unit}"
destdir="${classes}" />
</target>
<!-- Create the time stamp for reports-->
<target name="create.report.timestamp" depends="compile.unit">
<tstamp>
<format pattern="yyyy-MM-dd_HH'h'mm'm'ss's'" property="buildtime"/>
</tstamp>
<echo message="buildtime=${buildtime}"/>
</target>
<!-- junit test *Test.class in ${unit} -->
<target name="junit" depends="create.report.timestamp"
description="runs all unit tests and makes xml reports">
<echo message="creating report directory and running all junit tests"/>
<mkdir dir="${reports}/testsuite_${buildtime}"/>
<junit printsummary="on" fork="false" haltonfailure="false"
failureproperty="tests.failed" filtertrace="off" showoutput="true">
<formatter type="xml" usefile="true"/>
<batchtest todir="${reports}/testsuite_${buildtime}">
<fileset dir="${unit}">
<include name="**/*.java"/>
</fileset>
</batchtest>
</junit>
<echo message="reporting all junit tests"/>
<junitreport todir="${reports}/testsuite_${buildtime}">
<fileset dir="${reports}/testsuite_${buildtime}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}/testsuite_${buildtime}"/>
</junitreport>
<fail if="tests.failed">
One or more tests failed!!!!!!!!!!!!!!!
</fail>
</target>
<!--create jar and put in ${dist} -->
<target name="jar"
description="jars everything in ${package} into ${package}/${dist}/jar_${buildtime}"
depends="create.report.timestamp">
<mkdir dir="${dist}/jar-${buildtime}"/>
<jar jarfile="${dist}/jar-${buildtime}/${package}.jar" basedir="${classes}"/>
</target>
<!--create javadocs and put in ${docs} -->
<target name="javadoc"
description="making javadocs from ${src}/${package} and putting in ${docs}/${package}"
depends="jar">
<javadoc
destdir="${docs}"
author="true"
version="true"
use="true"
windowtitle="Torsten Test API">
<fileset dir="${src}" defaultexcludes="yes">
<include name="*.java" />
</fileset>
<doctitle><![CDATA[<h1>Test</h1>]]></doctitle>
<bottom><![CDATA[<i>Copyright © 2000 Torsten Sander. All Rights Reserved.</i>]]></bottom>
<tag name="todo" scope="all" description="To do:" />
<group title="Group 1 Packages" packages="com.dummy.test.a*"/>
<group title="Group 2 Packages" packages="com.dummy.test.b*:com.dummy.test.c*"/>
<link offline="true" href="http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
<link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
</javadoc>
</target>
<target name="all" description="Runs all targets in build file"
depends="compile, compile.unit, junit, jar, javadoc">
<echo message="All ant tasks have been run"/>
</target>
</project>
Nu har jeg det problem, at når jeg kører filen, virker testen ikke. I rapporten kommer følgende besked:
countLettersTest
java.lang.ClassNotFoundException: countLettersTest ......
Jeg går ud fra den ikke kan finde .java filen, men den ligger i unit folderen, så jeg ved ikke hvad der går galt.
Er der nogen der kan hjælpe??