Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Packages, Classpath, Ant, and JUnit (setting up a nice environment)

807601Feb 23 2008 — edited Feb 25 2008
Hi,

I am seeking a little help getting up and running, creating a nice environment where I can build a Java project, including building with Ant and using JUnit - hopefully this is the right forum. I am having some trouble in getting JUnit to run my tests properly (it is installed and findable by my Java install) and I think this is due to a package/classpath issue that is currently outside my experience. Here's my setup to explain:

I have installed the JUnit jar in my extensions folder, and it works properly (I can call it, don't get errors about JUnit), however, when I run my test I get the error:

"Could not find class: org.xxx.powersim.ModelTest
Time: 0
OK (0 tests)
Java Result: 1"


ModelTest has been compiled properly without error, and looks like this:
package org.xxx.powersim;

import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;

public final class ModelTest {
	
	public static void main(String args[]) {
	      org.junit.runner.JUnitCore.main("org.xxx.powersim.ModelTest");
	    }
	
	@Test
	public void testJunit() {
		assertTrue(true);
	}
}
Pretty simple stuff.

As you can see I'm trying to use the 'main' method of the test to execute the test itself... but I've tried running it via the runner from the command line also: "java org.junit.runner.JUnitCore org.xxx.powersim.ModelTest". I get the same result.

It might be a package issue, so here's how I have things set up in the file system:
PowerSim
	/build
		/org
			/xxx
				/powersim
					- ModelTest.class
	/src
		/org
			/xxx
				/powersim
					-ModelTest.java
I've tried running it within Ant, by hand using the runner, by hand calling the main method, and from within TextMate's built-in bundle - I get the same result. JUnit is installed and running fine, but it can't seem to see the test class - the more I think about it this is a package problem that I'm just not sure how to fix. I've tried running it by hand in the root /PowerSim directory, in the /build folder, and in the /powersim folder where ModelTest is. I still get the error that "Could not find class: org.xxx.powersim.ModelTest".

My files compile just fine with my simple Ant script which is as follows:

<?xml version="1.0"?>
<project name="PowerSim" default="run" basedir=".">
 <property name="src" value="./src"/>
 <property name="build" value="./build"/>
 <property name="compile.debug"       value="true"/>

 <path id="compile.classpath">
   <pathelement location="${mysql.jdbc}"/>
   <pathelement location="${junit.jar}"/>
 </path>

   <target name="build" depends="init">
       <javac srcdir="${src}"
              destdir="${build}"
              debug="${compile.debug}"
              source="1.5">
          <classpath refid="compile.classpath"/>
       </javac>
   </target>


 <target name="init">
   <mkdir dir="${build}"/>
 </target>


 <target name="run" depends="build">
   <java classname="org.xxx.powersim.Model"
       fork="true"
       dir="${build}"
       classpath="${build}"
       maxmemory="500m">
   </java>
   </target>

	<target name="test" depends="build">
	    <java classname="org.xxx.powersim.ModelTest"
	        fork="yes"
	        dir="${build}"
	        classpath="${build}"
	        maxmemory="500m">
	    </java>
	    </target>

 <target name="clean" description="Removes previous build">
   <delete verbose="true">
     <fileset dir="${build}"/>
   </delete>
 </target>

</project>
As you can see, I'm not sure what to try next - any help would be much appreciated.

I've tried adding things to my $CLASSPATH. For example I've added the root folder of the project, 'PowerSim' to my classpath, but this appears to have no effect. I am running OS X 10.5.

Thanks again for any help you may be able to offer, it will be very much appreciated,

- Peter
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2008
Added on Feb 23 2008
2 comments
448 views