Grails 3.3 Unit Tests (vs Grails 2.4)

I’ve spent some of this weekend migrating an old Grails 2.0 application to Grails 3.3. It went pretty well. I created a new project and then copied domain, controller and service classes over. There is still some work to do, migrating tests and refactoring code to use the asset pipeline.

Here I share what I’ve learned about the changes between unit tests in Grails 2.4 and 3.3.

  1. IntelliJ IDEA 16 doesn’t properly support Grails 3.3 yet
  2. Grails 2.4 and 3.3 on the same machine sometimes collide
  3. Domain/service mocking has changed since 2.4

Intellij IDEA Support

I’ve run in to problems running tests in another project. The tests run just fine from the command line, but not in IDEA. With further reading last night I found that IDEA fails to add “-integration” or “-unit” to the run/debug configuration commands. This results in Grails reporting no tests found. It should look like something like test-app AreaControllerSpec -echoOut -unit.

Once I added this the test ran but be aware that IDEA continues to report “Test framework quit unexpectedly” in all cases. If you ignore this, and perhaps use the very pretty HTML formatted reports, you can make progress.

Grails 2.4/3.3 Conflict

The main project that I’m working on is 2.4. When I tried to run the tests from the command line (as noted above) but they failed to even start, reporting missing dependencies (junit-dep and cglib-nodep).

 :: junit#junit-dep;4.10: not found
 :: cglib#cglib-nodep;2.2.2: not found

The found that the tests needed to be run from within IDEA.

Domain/Service Mocking

A key test that I have migrated is a controller integration test in the 2.0 project. I copied the methods over to a unit test and then needed to mock the domain objects and the services that were called by the controller. (The examples on the Grails documentation website didn’t show how to do this; how unrealistic is it to give an example with no reference to services?) Notice the lack of @Mock annotations.

import grails.testing.gorm.DataTest
import grails.testing.web.controllers.ControllerUnitTest
import org.grails.testing.GrailsUnitTest
import spock.lang.Specification

class AreaControllerSpec extends Specification implements
 ControllerUnitTest<AreaController>, DataTest, GrailsUnitTest {
def setup() {
    defineBeans {
    mockDomains Area, Company


One useful link is this commit on GitHub. It’s not exactly readable but it gives the changes implemented to arrive at the new testing framework.