Feb 16, 2009

Unit Testing Grails in Eclipse


For the past several weeks, I’ve been working on a Grails app in my spare time, and I’m really excited about the future of Grails.  However, I’ve been a bit disappointed in the tooling currently available.  Myself and many of my clients use Eclipse, and at this point the Eclipse support for Grails is less than ideal.


Spring Source’s recent acquistion of G2One will really help move the Eclipse support forward.  Here’s a recent interview with Grails founder Graeme Rocher in which he discusses how Spring Source will help drive Grails tool support within Eclipse.


http://www.grailspodcast.com/blog/id/109


One of the largest frustrations I’ve had with the Eclipse plugin is the setup necessary to run a grails unit test.  After I first setup my grails project in Eclipse, I tried to create a simple groovy unit test and run it.  As with Java unit tests, I right clicked on the class and selected run as junit test.  Each time I ran the test I received the following error.


“Error running MyGroovyTest.groovy failed to find a class file, ensure the Groovy output folder is on the classpath”


After a lot of digging around I was finally able to work through these issues and figure out a way to execute grails unit tests within eclipse.  Here are the steps I used to get the tests working.  


  1. Right-click on the project and select Properties > Groovy Project Properties.
  2. Uncheck “Disable Groovy Compiler Generating Class Files”
  3. Modify the “Groovy compiler output location” to “bin-groovy”
  4. Select “Java Build Path”
  5. Modify the Default Output folder to “/bin” (I need to test this again to see if this step is required).
  6. From the same Java Build Path dialog select Libraries > Add Class Folder…
  7. Check bin-groovy.
  8. Now run the unit test by right clicking on the groovy file and it should work.


It’s quite an involved process, but it works.  If anyone has a simpler solution, I’d be really glad to hear it.  I’m using Eclipse Ganymede, Grails 1.0.4, and Groovy Plugin 1.5.6.200807211457.  


Cleaning up these types of issues within Eclipse will be critical to the success of Grails, and I’m glad to hear that SpringSource and Grails will be focusing their efforts on tooling in the near future.


About the Author

David Reines profile.

David Reines

VP - Technology

David has led the development efforts of several mission-critical enterprise applications in the Twin Cities area. During this time, he has worked very closely with numerous commercial and open source JEE technologies. David has extensive experience in the architecture, design, implementation, deployment and support of highly scalable business applications.

Leave a Reply

Your email address will not be published.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]