Jun 2, 2009

Running and Debugging Grails Integration Tests In Eclipse

This is a follow on to Eclipse Setup for Grails 1.1 Development.
Although not ideal Eclipse integration, by setting up a Run Configuration for your Grails project in Eclipse, you will be able to run and debug Grails integration JUnit tests within Eclipse.  Here is how:

  • Open Run Configurations
  • Select Java Applications->New
  • On the Main tab:
    Select your Grails project
    Main class:  org.codehaus.groovy.grails.cli.support.GrailsStarter
  • On Arguments tab:
    Program args (Including the quotes):  “test-app ${string_prompt} -integration”
    VM Arguments: -Dgrails.home=${grails_home} -Dbase.dir=”${project_loc:<your project>}” -Dgrails.env=development -Xms512M -Xmx768M -XX:PermSize=64M -XX:MaxPermSize=128M
  • On Classpath tab:
    User Entries add your project
    User Entries add all $GROOVY_HOME/dist and $GROOVY_HOME/lib jar files (to be safe)
  • On Source tab add your Java Project for debugging purposes
  • On Environment tab you have to add a JAVA_HOME and GRAILS_HOME environment variable.
  • On Common tab Display in Run and Debug Favorites menus
  • Apply and Done

Try it out.  Let’s say you have integration tests for a controller called SomeController.  When you run this new run configuration, when prompted type in SomeController.  The results of test will be shown in the console and the test report will be generated in <your project>/test/reports (you will have to manually re-sync to refresh the reports.

Now try setting a breakpoint in a test within the integration test case for SomeController.  Now run the debug configuration version of the setup you did above.  Again, when prompted enter SomeController. Eclipse should stop at your breakpoint.  Now you can debug your integration test within Eclipse without having to manually setup a remote debugger.

About the Author

Torey Lomenda profile.

Torey Lomenda

VP - Solution Delivery

Torey is a Chief Technologist at Object Partners Inc. specializing in Mobile & Enterprise technologies with over 19 years of professional experience. Most recently he has led a number of iOS-related projects, applying his expertise in building HTML5 and Native Objective-C & Swift-based apps for iOS (iPad/iPhone). He has led the development of various mission-critical applications and supports a pragmatic delivery approach using various agile methodologies. During his career he has gained expertise with iOS, Java/JEE ecosystem and its related open source (ie: Spring-related, Tomcat), Groovy/Grails, JavaScript & technologies (ExtJS, AngularJS) to deliver rich internet applications (RIAs), and various commercial technologies (ie: IBM/Tivoli, Oracle, Tibco).

One thought on “Running and Debugging Grails Integration Tests In Eclipse

  1. Kit Plummer says:

    Hey. Thanks for this!

    One issue I had was in the VM arguments where you have:

    VM Arguments: -Dgrails.home=${grails_home} -Dbase.dir=”${project_loc:}” -Dgrails.env=development -Xms512M -Xmx768M -XX:PermSize=64M -XX:MaxPermSize=128M

    I had to remove the -Dbase.dir=”${project_loc}” bit because it was added it twice. Other than that – perfect. Thanks again.

  2. Edvinas says:

    Great post!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Android Development for iOS Developers
Android development has greatly improved since the early days. Maybe you tried it out when Android development was done in Eclipse, emulators were slow and buggy, and Java was the required language. Things have changed […]
Add a custom object to your Liquibase diff
Adding a custom object to your liquibase diff is a pretty simple two step process. Create an implementation of DatabaseObject Create an implementation of SnapshotGenerator In my case I wanted to add tracking of Stored […]
Keeping Secrets Out of Terraform State
There are many instances where you will want to create resources via Terraform with secrets that you just don’t want anyone to see. These could be IAM credentials, certificates, RDS DB credentials, etc. One problem […]
Validating Terraform Plans using Open Policy Agent
When developing infrastructure as code using terraform, it can be difficult to test and validate changes without executing the code against a real environment. The feedback loop between writing a line of code and understanding […]