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.

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 *

*

*