aspose file tools*
The moose likes Testing and the fly likes Novie JUNIT user need helps - NoClassDefFoundError + bash + windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Novie JUNIT user need helps - NoClassDefFoundError + bash + windows" Watch "Novie JUNIT user need helps - NoClassDefFoundError + bash + windows" New topic
Author

Novie JUNIT user need helps - NoClassDefFoundError + bash + windows

Michael Goodman
Greenhorn

Joined: Jul 17, 2006
Posts: 3
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Michael Goodman
Greenhorn

Joined: Jul 17, 2006
Posts: 3
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
Sounds like it. You can get your JVM's version by typing "java -version" on the command prompt.
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
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.


aldana software engineering blog & .more
Michael Goodman
Greenhorn

Joined: Jul 17, 2006
Posts: 3
Thanks for the helps!!

I do have an out-dated jave (v1.4.0_1) and I'll get it updated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Novie JUNIT user need helps - NoClassDefFoundError + bash + windows