4 Using the Test Compatibility Kit - Reference Documentation
Authors: Graeme Rocher
Version: 5.0.8.RELEASE
4 Using the Test Compatibility Kit
Thegrails-datastore-gorm-tck
project provides a few hundred tests that ensure a particular GORM implementation is compliant. To use the TCK you need to define a dependency on the TCK in the subprojects build.gradle
file:testCompile project(':grails-datastore-gorm-tck')
Setup.groovy
file that sets up your custom datastore in your implementation.For example the ConcurrentHashMap
implementation has one defined in grails-datastore-gorm-test/src/test/groovy/org/grails/datastore/gorm/Setup.groovy
:class Setup { static destroy() { // noop } static Session setup(classes) { def ctx = new GenericApplicationContext() ctx.refresh() def simple = new SimpleMapDatastore(ctx) … for (cls in classes) { simple.mappingContext.addPersistentEntity(cls) } … def enhancer = new GormEnhancer(simple, new DatastoreTransactionManager(datastore: simple)) enhancer.enhance() simple.mappingContext.addMappingContextListener({ e -> enhancer.enhance e } as MappingContext.Listener) simple.applicationContext.addApplicationListener new DomainEventListener(simple) simple.applicationContext.addApplicationListener new AutoTimestampEventListener(simple) return simple.connect() } }
Setup.groovy
class should initiase the Datastore
and return a Session
from the static setup
method which gets passed a list of classes that need to be configured.With this done all of the TCK tests will run against the subproject. If a particular test cannot be implemented because the underlying datastore doesn't support the feature then you can create a test that matches the name of the test that is failing and it will override said test.For example SimpleDB doesn't support pagination so there is a grails.gorm.tests.PagedResultSpec
class that overrides the one from the TCK. Each test is a Spock specification and Spock has an Ignore
annotation that can be used to ignore a particular test:/** * Ignored for SimpleDB because SimpleDB doesn't support pagination */ @Ignore class PagedResultSpec extends GormDatastoreSpec{ … }