How to configure Groovy + Eclipse + Junit4?

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

Unfortunately, after 4 hours of trial error, I still cannot configure correctly. I tried using the Eclipse Junit4 test runner to run a Groovy file with a method annotated for testing using @Test. But he keeps complaining about a NoClassDefFoundException

Can anybody help?

Here is the contents of my Groovy file called simpleTest.groovy

import org.junit.Test import static org.junit.Assert.assertEquals class simpleTest{ @Test void trial(){ assertEquals 6, 3+3 } } 

Anyone can help?

+6
eclipse junit groovy
source share
4 answers

You might want to update the plugin, see the last blog post for more details. The theme of this alpha release is an optimized editing / saving / compilation / testing process that seems to be your specific use case.

Groovy Eclipse 2.0

+3
source share

This works for me in my environment, so here is a brief overview of what I have:

In the startup dialog under JUnit:

  • Test Tab:. The testing class must already be compiled by the Groovy plugin.
  • Class path: All Jar files from my project, as well as the Groovy library library

In the window-> Settings-> Java-> Build Path

  • Class variables:
      GROOVY _ECLIPSE _HOME 
    = location where the Groovy plugin is installed

It does the trick for me.

+1
source share

Unfortunately, the Groovy Eclipse plugin is pretty terrible at providing actual useful information so you know what is wrong with your setup. I'm going to assume that you have already performed a check to make sure that the plugin actually creates your Groovy files (i.e., makes a sample without dependencies, checks the output directory correctly, etc.). After that, he has a lot of really small configuration checks ... I ran into problems when the particular โ€œrunnerโ€ that I use in Eclipse (ie, on the Run menu) does not have the name of the recording class defined there, or by for some reason my project wasnโ€™t 'correctly injecting the dependency of the JUnit library into it.

Ultimately, it may be a headache for the configuration, but in the long run, you will end up saving time and getting great functionality if you can knock it out ...

0
source share

I ran into a similar problem, and it was the missing batch request that caused me problems. Groovy The Eclipse plugin did not complain about it, but my class was present in the package. I got noClassDefError when running the file as a JUnit test.

Adding the package statement to the top of the class solved this problem.

0
source share

All Articles