I am working on a small webapp and I want to use Groovy to write some unit testing for my app. Most of my coding is done on Eclipse and I really want to run all the unit testing with the graphical test runner within Eclipse (I really like the green bar :) )

Sadly, after 4 hours of try-and-error, I'm still not able to setup properly. I tried to use the Eclipse Junit4 test runner to run a Groovy file with method annotated for testing using @Test. But it keeps complaining NoClassDefFoundException

Anyone can help?

Here is content of my groovy file, named simpleTest.groovy

import org.junit.Test
import static org.junit.Assert.assertEquals

class simpleTest{
  void trial(){
    assertEquals 6, 3+3

Anyone can help?


What is the NoClassDefFound error you are receiving? That may help determine what is going on.

Sam Merrell

Unfortunately, the Groovy Eclipse plugin is pretty horrible at giving actual helpful information to let you know what is going wrong with your setup. I'm going to assume you already did the verification to make sure the plugin is actually building your Groovy files (i.e. doing a sample with no dependencies, checking the properly output directory, etc...) After that, it's a lot of really small configuration verification...I've run into problems where the particular "runner" I'm using in Eclipse (i.e. in the Run menu) doesn't have the write class name defined there or for some reason my project didn't get the JUnit library dependency properly inserted into it.

Ultimately, it can be a configuration headache, but long term you'll end up saving some time and gaining some cool functionality if you can knock it out...

+1  A: 

I have this working in my environment so here is a brief summary of what I have:

In the run dialog under JUnit:

  • Test Tab: The test class, this must have already been compiled by the Groovy plugin.
  • Classpath: All of the Jar files from my project as well as the Groovy Libraries library

In Window->Preferences->Java->Build Path

  • Classpath Variables:
    = the location where the Groovy plugin is installed

That does the trick for me.

Peter Kelley

Is there a easy, reproducible way of setting this up? I'm also having trouble doing this. Followed your guidelines and still wasn't able to run tests.

+1  A: 
Robert Munteanu
that helped me alot, ty :)