Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Novie JUNIT user need helps - NoClassDefFoundError + bash + windows

 
Michael Goodman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

This is my very first post here so I really appreciate any helps I can get from this forum.

I just installed junit-4.1 today and try to run a sample test but without success. I received 'java.lang.NoClassDefFoundError' error but not sure why. Here is my setup:

1. I'm running the test on Windows XP machine under 'cygwin/bash'
2. I have installed junit-4.1 on my machine @ c:/junit (I renamed junit-4.1 to junit, I also renamed junit-4.1.jar to junit.jar)
3. I added the following lines in my .bashrc file:
JUNIT_HOME=/cygdrive/c/junit
CLASSPATH=$JUNIT_HOME/junit.jar
export JUNIT_HOME CLASSPATH
4. In my bash window, I 'cd' to c:/junit/junit/samples directory and typed:
$ java junit.textui.TestRunner junit.samples.AllTests
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner

Quetions:
1. What did I do wrong?
2. Why the returned error message shows '/' instead of '.'? Am I using the wrong JVM? (/cygdrive/c/WINDOWS/system32/java)
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some questions that might (or might not) lead to a solution...

Originally posted by Michael Goodman:
3. I added the following lines in my .bashrc file:
JUNIT_HOME=/cygdrive/c/junit
CLASSPATH=$JUNIT_HOME/junit.jar
export JUNIT_HOME CLASSPATH

Did you also "source" your .bashrc file or start a new cygwin session? If you didn't, the .bashrc file hasn't been executed yet and thus your CLASSPATH is missing the junit.jar file.

Originally posted by Michael Goodman:
4. In my bash window, I 'cd' to c:/junit/junit/samples directory and typed:
$ java junit.textui.TestRunner junit.samples.AllTests
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner

Try executing the following:
$ java -classpath "c:/junit-4.1/junit.jar;c:/junit-4.1" junit.textui.TestRunner junit.samples.AllTests

Originally posted by Michael Goodman:
2. Why the returned error message shows '/' instead of '.'? Am I using the wrong JVM? (/cygdrive/c/WINDOWS/system32/java)

The return message uses "/" instead of "." simply by convention--nothing to worry about. Whether or not you're using the wrong JVM, depends on the version of the JVM the binary in your system32 folder is part of. (You need Java 1.5.x for running JUnit 4)
 
Michael Goodman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lasse! I did source the .bashrc and I added '-classpath' from the command line. Now I'm getting a different error message. Does it mean that I need to install a newer JVM?

$ java -classpath "c:/junit/junit.jar;c:/junit" junit.textui.TestRunner junit.samples.AllTests
Exception in thread "main" java.lang.UnsupportedClassVersionError: junit/textui/TestRunner (Unsuppor
ted major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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.loadClassInternal(Unknown Source)
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like it. You can get your JVM's version by typing "java -version" on the command prompt.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remember, that JUnit 4 needs Java 1.5 runtime.

if you are not familiar with Java 1.5 and JUnit in general go for JUnit 3.x test cases, so you don't get overwhelmed by two new technologies. so concentrate to grasp concepts of JUnit first.

you can run JUnit 3.x style tests under JUnit 4.
 
Michael Goodman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the helps!!

I do have an out-dated jave (v1.4.0_1) and I'll get it updated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic