1 Reply Latest reply: Aug 24, 2007 7:22 AM by 807600 RSS

    manged to get separate test ant - can't understand error log

    807600
      Hi,
      I managed to get a simple example of Junit running through ANT building but not testing correctly.
      my example test class looks like:
      package com.sims.test;
      
      
      public class HelloWorldTest extends junit.framework.TestCase {
      
          public void testNothing() {
          }
          
          public void testWillAlwaysFail() {
              assertEquals("", "");
          }
          
      }
      this runs fine through eclipse with as a JUnit application.

      my buildfile looks like:
      <project name="TestHelloWorld" default="test" basedir=".">
      
           <property name="test" location="C:/myProjects/runway_core/guitools/sims/build/classes/com/sims/test"/>
      
           <property name="tests.src" location="${basedir}"/>
      
      
           <path id="test.class.path">
           <pathelement path="C:/eclipse-SDK-3.2.1-win32/eclipse/plugins/org.junit_3.8.1/junit.jar"/>                   
                
           <!-- the test classes are all in here -->
           <pathelement location="${test}"/>
           </path>
      
      
           <!-- Build of the Junit test -->
           <target name="build-tests" description="Build the Junit test">
             <javac srcdir="${tests.src}" destdir="${test}">
               <classpath refid="test.class.path"/>
             </javac>
           </target>
                
           <!-- Run of the Junit test -->
           <target name="test" description="Run the Junit test"
                      depends="build-tests">
             <junit printsummary="yes" haltonfailure="no">
               <classpath refid="test.class.path"/>
                 <formatter type="plain"/>
                 <test name="com.sims.test.HelloWorldTest" outfile="result"
                          todir="${test}"/>
             </junit>
           </target>  
                
           </project>
      Now it build fine, but when I click on 'test' in the Ant perspective of Eclipse it returns:

      Buildfile: C:\myProjects\runway_core\guitools\sims\src\com\sims\test\fileListingbuild.xml
      build-tests:
      test:
      [junit] Running com.sims.test.HelloWorldTest
      [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
      [junit] Test com.sims.test.HelloWorldTest FAILED
      BUILD SUCCESSFUL
      Total time: 1 second
      to the console.

      and there is a log file with:

      Testsuite: com.sims.test.HelloWorldTest
      Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

           Caused an ERROR
      com.sims.test.HelloWorldTest
      java.lang.ClassNotFoundException: com.sims.test.HelloWorldTest
           at java.net.URLClassLoader$1.run(Unknown Source)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClass(Unknown Source)
           at java.lang.ClassLoader.loadClassInternal(Unknown Source)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Unknown Source)
           at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
           at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
           at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

      I know I probably am doing something simple wrong but can't figure it out.

      Thanks,

      Tri