(Quick Reference)



A mixin for setting up unit testing of datastores such as the Mongo datastore.


import grails.datastore.test.DatastoreUnitTestMixin

@Mixin(DatastoreUnitTestMixin) class PersonTests extends GroovyTestCase { void testPersist() { mockDomain(Person) def s = new Person(name:"Bob") s.save()

assert s.id != null

s = Person.get(s.id)

assert s != null }

void tearDown() { disconnect() } }


DatastoreUnitTestMixin allows you to test datastore interactions by mocking the complete GORM API including simple persistence methods, dynamic finders, criteria queries and named queries.

If you want to make sure that tests do not share data, add an implementation of tearDown() (or the equivalent in your test framework) that calls the disconnect() method. Also make sure to call the super class method if necessary!