|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | PROPERTY | CONSTR | METHOD | DETAIL: FIELD | PROPERTY | CONSTR | METHOD |
java.lang.Object GroovyTestCase grails.test.GrailsUnitTestCase
class GrailsUnitTestCase extends GroovyTestCase
Support class for writing unit tests in Grails. It mainly provides access to various mocking options, while making sure that the meta- class magic does not leak outside of a single test.
Property Summary | |
---|---|
java.lang.Object |
applicationContext
|
DefaultArtefactInfo |
domainClassesInfo
Keeps track of the domain classes mocked within a single test so that the relationships can be configured for cascading validation. |
java.util.Map |
errorsMap
|
java.util.Set |
loadedCodecs
|
java.util.Map |
savedMetaClasses
|
Method Summary | |
---|---|
protected void
|
addConverters(java.lang.Class clazz)
|
protected void
|
enableCascadingValidation()
Enables the cascading validation support for domain classes. |
protected void
|
loadCodec(java.lang.Class codecClass)
Loads the given codec, adding the "encodeAs...()" and "decode...()" methods to objects. |
protected void
|
mockConfig(java.lang.String config)
|
protected void
|
mockController(java.lang.Class controllerClass)
Mocks a controller class, providing implementations of standard methods like render and redirect |
protected void
|
mockDomain(java.lang.Class domainClass, java.util.List instances = [])
Mocks a domain class, providing working implementations of the standard dynamic methods. |
protected GrailsMock
|
mockFor(java.lang.Class clazz, boolean loose = false)
Creates a new Grails mock for the given class. |
protected void
|
mockForConstraintsTests(java.lang.Class clazz, java.util.List instances = [])
Mocks the given class (either a domain class or a command object) so that a "validate()" method is added. |
protected void
|
mockLogging(java.lang.Class clazz, boolean enableDebug = false)
Provides a mock implementation of the "log" property for the given class. |
protected void
|
mockTagLib(java.lang.Class tagLibClass)
Mocks a tag library, providing the common web properties as well as "out", "throwTagError()", and an implementation of the "render" tag. |
protected void
|
registerMetaClass(java.lang.Class clazz)
Use this method when you plan to perform some meta-programming on a class. |
protected void
|
setUp()
|
protected void
|
tearDown()
|
Property Detail |
---|
java.lang.Object applicationContext
DefaultArtefactInfo domainClassesInfo
java.util.Map errorsMap
java.util.Set loadedCodecs
java.util.Map savedMetaClasses
Method Detail |
---|
protected void addConverters(java.lang.Class clazz)
protected void enableCascadingValidation()
protected void loadCodec(java.lang.Class codecClass)
codecClass
- The codec to load, e.g. HTMLCodec.
protected void mockConfig(java.lang.String config)
protected void mockController(java.lang.Class controllerClass)
protected void mockDomain(java.lang.Class domainClass, java.util.List instances = [])
domainClass
- The class to mock.instances
- An optional list of domain instances to use
as the data backing the dynamic methods.
protected GrailsMock mockFor(java.lang.Class clazz, boolean loose = false)
clazz
- The class to mock.loose
- If true
, the method returns a loose-
expectation mock, otherwise it returns a strict one. The default
is a strict mock.
protected void mockForConstraintsTests(java.lang.Class clazz, java.util.List instances = [])
protected void mockLogging(java.lang.Class clazz, boolean enableDebug = false)
enableDebug
argument.
clazz
- The class to add the log method to.enableDebug
- An optional flag to switch on printing of
debug statements.
protected void mockTagLib(java.lang.Class tagLibClass)
protected void registerMetaClass(java.lang.Class clazz)
clazz
- The class to register.
protected void setUp()
protected void tearDown()
Groovy Documentation