<p>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 :) )</p>

<p>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 <code>@Test</code>. But it keeps complaining <code>NoClassDefFoundException</code></p>

<p>Anyone can help? </p>

<p>Here is content of my groovy file, named simpleTest.groovy</p>

<pre><code>import org.junit.Test
import static org.junit.Assert.assertEquals

class simpleTest{
  @Test
  void trial(){
    assertEquals 6, 3+3
  }
}
</code></pre>

<p>Anyone can help?</p>

[{'answer_id': 55705, 'author': 'Kivus', 'author_id': 5590, 'author_profile': 'https://Stackoverflow.com/users/5590', 'pm_score': 0, 'selected': False, 'text': '<p>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. </p>\n\n<p>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...</p>\n'}, {'answer_id': 79907, 'author': 'Peter Kelley', 'author_id': 14893, 'author_profile': 'https://Stackoverflow.com/users/14893', 'pm_score': 1, 'selected': False, 'text': '<p>I have this working in my environment so here is a brief summary of what I have:</p>\n\n<p>In the run dialog under JUnit:</p>\n\n<ul>\n<li><strong>Test Tab:</strong> The test class, this must have already been compiled by the Groovy plugin.</li>\n<li><strong>Classpath:</strong> All of the Jar files from my project as well as the <em>Groovy Libraries</em> library</li>\n</ul>\n\n<p>In Window->Preferences->Java->Build Path</p>\n\n<ul>\n<li><strong>Classpath Variables:</strong> <pre>GROOVY<code>_ECLIPSE</code>_HOME</pre> = the location where the Groovy plugin is installed</li>\n</ul>\n\n<p>That does the trick for me.</p>\n'}, {'answer_id': 1215323, 'author': 'Robert Munteanu', 'author_id': 112671, 'author_profile': 'https://Stackoverflow.com/users/112671', 'pm_score': 2, 'selected': False, 'text': '<p>You might want to give the updated plugin a try, see the <a href="http://blog.springsource.com/2009/07/30/a-groovier-eclipse-experience" rel="nofollow noreferrer">the recent blog post</a> for more details. The theme of this alpha release is <em>providing an optimized edit/save/compile/test experience</em>, which seems to be your exact use case.</p>\n\n<p><img src="https://i.stack.imgur.com/0joPq.png" alt="Groovy Eclipse 2.0"></p>\n'}, {'answer_id': 4826104, 'author': 'Arun R', 'author_id': 211967, 'author_profile': 'https://Stackoverflow.com/users/211967', 'pm_score': 0, 'selected': False, 'text': '<p>I had faced a similar issue and it was the missing package statement that caused me to have problems. Groovy Eclipse plugin did not complain about it but my class was present in a package. I got the noClassDefError when running the file as a JUnit Test.</p>\n\n<p>Adding the package statement to top of class solved this issue.</p>\n'}]
['https://Stackoverflow.com/questions/9928', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']