[Biojava-l] Re: Unit tests
Michael L. Heuer
heuermh@acm.org
Mon, 14 May 2001 13:53:47 -0400 (EDT)
Matthew Pocock wrote:
> Is there any way to get ant to put the test & src files into seperate
> build directories? That way the resulting biojava.jar can trivialy not
> contain any test code.
This may not be the cleanest way, but my ant build files are like
<property name="src.dir" value="./src/java" />
<property name="test.home" value="./src/test" />
<property name="test.runner" value="junit.textui.TestRunner" />
<property name="test.failonerror" value="true" />
<property name="lib.dir" value="./lib"/>
<property name="build.dir" value="./build" />
<property name="build.src" value="./build/src" />
<property name="build.test" value="./build/test" />
<property name="build.dest" value="./build/classes" />
<property name="build.javadocs" value="./build/docs" />
</target>
<!-- Compiles the source directory -->
<target name="compile" depends="init,prepare-src">
<javac srcdir="${build.src}" destdir="${build.dest}">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- Compiles the tests -->
<target name="compile.tests" depends="compile">
<javac srcdir="${test.home}" destdir="${build.test}">
<classpath>
<pathelement path="${build.dest}" />
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${junit.home}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- Creates the class package -->
<target name="package" depends="init,compile">
<jar jarfile="${build.dir}/${name}.jar" basedir="${build.dest}"
manifest="${build.src}/${manifest.file}" includes="${jar.includes}"/>
<copy todir="">
<fileset dir="${build.dir}">
<include name="${name}.jar" />
</fileset>
</copy>
</target>
<target name="test" depends="compile.tests,test.[package]" />
<target name="test.[package]">
<java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
<arg value="[package].[Package]Test"/>
<classpath>
<pathelement path="${build.dest}" />
<pathelement path="${build.test}" />
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${junit.home}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</java>
</target>
where [package].PackageTest is either a TestCase or TestSuite as needed.
Hopefully I haven't snipped out any of the useful bits in this e-mail.
michael