Wednesday, January 6, 2010

Solution : JUNIT Setup \ 'java.lang.NoClassDefFoundError' error +Class not found "junit.samples.AllTests"

Follow the given steps:

  1. Download the Junit from the sourceforge repository.(Download Link) , the Zip file
  2. extract the zip file to a directory. ex c:\
  3. it should look like c:\junit4.8.1\ with folders ex. doc, javadoc etc
  4. Add the paths 
    • JUNIT_HOME=c:\junit4.8.1
    • CLASSPATH=c:\junit4.8.1\junit-4.8.1.jar;c:\junit4.8.1
  5. open a new command window
  6. go to the C:\junit4.8.1 folder
  7. try following java junit.textui.TestRunner junit.samples.AllTests
.........................................
.........................................
.........................................
.......
Time: 0.453
OK (130 tests)


else try running the command line version

C:\junit4.8.1>java -classpath "C:\junit4.8.1\junit-4.8.1.jar;c:\junit4.8.1" junit.textui.TestRunner junit.samples.AllTests

Output should be like below

.........................................
.........................................
.........................................
.......

Time: 0.422
OK (130 tests)

if this does not work that means you may be using wrong java version. (I have tested junit 4.8.1 working with JDK 5)

- Mihir Patel.

3 comments:

Anonymous said...

Thanks yaar....it helped me a lot during my internship period.

--Bhavesh Furia

Anonymous said...

Thank you. It was really helpful!

Anonymous said...

very good - glad i found this - looks like the Test.Runner and AllTest need different classpath