(Quick Reference)
DatastoreUnitTestMixin
Purpose
A mixin for setting up unit testing of datastores such as the Redis datastore.
Examples
import grails.datastore.test.DatastoreUnitTestMixin@Mixin(DatastoreUnitTestMixin)
class PersonTests extends GroovyTestCase {
void testPersist() {
mockDomain(Person)
def s = new Simple(name:"Bob")
s.save() assert s.id != null s = Simple.get(s.id) assert s != null
} void tearDown() {
disconnect()
}
}
Description
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!