April Randolph for IEEE April Randolph for IEEE - 7 months ago 20
Java Question

Ant Junit testing puttering out - need the summary

I'm using ant to build my java program. It's compiling fine but when I go to run the unit test class it can't find Class Files. I've messed with my classpath a ton and this exception keeps coming up?

The jars in lib are as follows:

  • ant.jar

  • hamcrest.jar

  • hamcrest-core-1.3.jar

  • hamcrest-all-1.3.jar

  • hamcrest-core.jar

  • junit.jar


<project name="PillarWorkspaceHiring" default="test" basedir=".">
Author: April Randolph for a evening of babysitting. Uses Ant to build the junit, hamcrest java program.
Babysitting Kata

<!-- Set global properties for this build -->
<property name="test.src.dir" value="src/main/java"/>
<property name="test.build.dir" value="build/test"/>
<property name="main.build.dir" value="build/main"/>
<property name="main.src.dir" value="src/main/java"/>
<property name="full-compile" value="true"/>

<target name="clean" description="clean up">
<!-- Delete the ${dir.build} -->
<delete verbose="${full-compile}" >
<fileset dir="${main.build.dir}" includes="**/*.class" />
<fileset dir="${test.build.dir}" includes="**/*.class" />
</target >

<path id="classpath.test">
<pathelement location="lib/junit-4.12.jar"/>
<pathelement location="lib/hamcrest-core-1.3.jar"/>
<pathelement location="lib/ant.jar"/>
<pathelement location="${main.build.dir}"/>

<!-- Testsuite-->
<target name="test" depends="test-compile" >
<junit printsummary="on" haltonfailure="yes" fork="true">
<path refid="classpath.test"/>
<pathelement location="${test.build.dir}"/>
<formatter type="brief" usefile="false" />
<fileset dir="${test.src.dir}" includes="**/*Test*.java" />

<!-- Build main class files -->
<target name="compile" >
<mkdir dir="${main.build.dir}"/>
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>

<target name="test-compile" depends="compile">
<mkdir dir="${test.build.dir}"/>
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>


inflated: hamcrest\SelfDescribing.class

I get this from the console


What am I doing wrong?


You need to add junit.jar and hamcrest-all-X.X.jar to your classpath.

you also need hamcrest-core-1.3.jar (for jUnit 4.11) in your lib folder.


Please follow the steps:

  1. Right click on the project.
  2. Choose Build Path Then from its menu choose Add Libraries.
  3. Choose JUnit then click Next.
  4. Choose JUnit4 then Finish.


  1. Go to Preferences | Java | JUnit
  2. Click "Add Package" and add "org.hamcrest.*"


If UPDATE1 not works then,

You can download JUnit 4.7 and put junit-4.7.jar in your build path (instead of the older version). That can solve your issue