‘Agile’ Integration Tests on Grails

Over the weekend I finally scrounged some mental space to write a small application to manage bookings for my badminton club. After debating between Ruby on Rails (RoR) and Grails, I decided on Grails.

As you might know Grails has very nice and expressive way of modeling the domain classes — arguably more elegant than RoR. And also that writing integration tests to experiment with the CRUD functionality makes writing a robust and testable model very simple.

So I wrote a bunch of integration tests as I was designing the domain classes. However, running the tests using grails test-app was proving to be very slow, and I mean really slow — 11 seconds to run tests on two domain classes.

Using grails test-app runs both unit and integration test. The actual time taken to run both the unit and integration tests wasn’t that much. It was the overall task of setting up the test environment that seemed to be taking a while.

So I experimented with a couple of options. You can chose to run only the unit or integration tests:

grails test-app -unit

grails test-app -integration

It is nicer in that one can run either unit or integration tests, but it still is quite time consuming as far as integration tests go.

To make a little more efficient, you can also just run integration tests on one class at a time:

grails test-app -integration className

This runs integration tests for only the class whose className is provided.

More information on this can be found in the Grails documentation.

Quicker, but still not fast enough to be called “agile”!

The final thing to try was to run the interactive Grails interactive shell:

grails interactive

This launches the Grails interactive shell in which you can issue various commands. So to test an app:


This takes a little while to setup the test environment etc., but once it is done, the next time you run test-app, Grails only takes the time to run actual tests, which is much faster and ‘agile’!

2 thoughts on “‘Agile’ Integration Tests on Grails”

  1. The fact that it is slow to write integration tests is one of the things that put me off using Grails in the first place (I had a rather slow computer at the time, which didn’t help) – and got me started on Impala, which uses dynamic modules and an interactive test runner to massively speed up running integration tests: http://impala.googlecode.com/. But it’s based on Spring/Java, so won’t help you if you’re already into Grails.

    For a large app with many integration points, I suspect running test-app is will take an increasingly large amount of time for the restarts that are necessary, unless there is some way you can slice and dice your application.

  2. I agree with you. The app that I was building was very simple with a few domain classes and controllers, so it wasn’t too much of a biggie in this project. But I do dread to think of how long it will take in a large-scale, enterprise-wide application.

    The key reason for me choosing Grails was that greater familiarity with Groovy and Java over Ruby. And not just familiarity, but also the ability to reuse existing Java/Groovy classes in Grails apps.

    Ruby on Rails, on the other hand, seems much quicker as far as testing and speed of development goes. There are some comparisons on the performance between Grails and RoR, which indicate that Grails is quicker, but I have a feeling that they might not stand up to the test.

    I hope to develop the same application with similar tests in RoR and see how the process goes. It’d give me a better idea of which technology to use, and in which scenario.

    Thanks for the link for Impala. I’ll check it out. If you manage to integrate it with Grails, I would be interested in looking at that as well.

Comment on this blog post...