blob: 4825f5d28a6893a8af3fff35ee9e898ff13e49e1 [file]
h1. DatastoreUnitTestMixin
h2. Purpose
A mixin for setting up unit testing of datastores such as the Redis datastore.
h2. Examples
{code}
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()
}
}
{code}
h2. 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!