tags:

views:

25

answers:

1

I can't get my Junit tests to run from my build.xml script. I feel like I have tried everything.

Here is my build.xml script.

 <property file="build.properties"/>
 <property name="src.dir" value="src"/>
 <property name="build.dir" value="classes"/>
 <property name="web.dir" value="war"/>
 <property name="test.dir" value="test"/>

 <path id="build.classpath">
     <fileset dir="lib">
      <include name="*.jar"/>
     </fileset>
     <!-- servlet API classes: -->
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
   </fileset>
   <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
</path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <path refid="classpath.base" />
 </path>

 <target name="build">
  <mkdir dir="${build.dir}"/>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"       deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
      <classpath refid="build.classpath" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"/>
   </javac>
  </target>

<target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.PracticeTest" />
    </junit>
  </target>

I am getting the following error message from the console.

test:
    [junit] Testsuite: com.mmz.mvc.test.PracticeTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Null Test:  Caused an ERROR
    [junit] com.mmz.mvc.test.PracticeTest
    [junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.PracticeTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:247)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\Eric\Documents\Java\mmz\WEB-INF\build.xml:44: Test com.mmz.mvc.test.PracticeTest failed

+1  A: 

I figured out how to get it to run my tests, but now it is telling me that my test is successful even though it is supposed to fail, I know it fails because I am testing

assertTrue("Example doesnt work",false);
CitadelCSAlum
+1 for answering your own question
ChrisH