0
votes

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

Buildfile build.xml:

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

<!-- 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" /> 
    </delete>
</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}"/>
</path>

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

<!-- 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"/>
    </javac>
</target>

<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"/>
    </javac>
</target>

</project>

inflated: hamcrest\SelfDescribing.class

I get this from the console

test:

What am I doing wrong?

1
Which version of JUnit do you use? - Stefan Birkner
@Stefan It turns out that I somehow uninstalled one of the frameworks that I needed and that was my problem. Now I am getting everything a SUCCESS although the test: only shows just that. (updated the question) - April_Nara
Remove lib/ant.jar from the classpath. - Stefan Birkner
@stefanBirkner still there's not an output to verify what's happening with my testsuite. - April_Nara

1 Answers

1
votes

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

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

UPDATE1:

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.

And

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

UPDATE2:

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