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.
Fields inherited from class | Fields |
---|---|
class groovy.util.GroovyTestCase |
TEST_SCRIPT_NAME_PREFIX |
Type | Name and description |
---|---|
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 |
Type Params | Return Type | Name and description |
---|---|---|
|
protected void |
addConverters(java.lang.Class clazz, boolean register = true) |
|
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 groovy.util.ConfigObject |
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() |
Methods inherited from class | Name |
---|---|
class groovy.util.GroovyTestCase |
groovy.util.GroovyTestCase#getName(), groovy.util.GroovyTestCase#getMethodName(), groovy.util.GroovyTestCase#assertEquals(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#assertEquals(java.lang.String, java.lang.String), groovy.util.GroovyTestCase#assertEquals(java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#notYetImplemented(), groovy.util.GroovyTestCase#notYetImplemented(java.lang.Object), groovy.util.GroovyTestCase#run(), groovy.util.GroovyTestCase#run(junit.framework.TestResult), groovy.util.GroovyTestCase#toString(), groovy.util.GroovyTestCase#format(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#setName(java.lang.String), groovy.util.GroovyTestCase#fail(java.lang.String), groovy.util.GroovyTestCase#fail(), groovy.util.GroovyTestCase#assertNotNull(java.lang.String, java.lang.Object), groovy.util.GroovyTestCase#assertNotNull(java.lang.Object), groovy.util.GroovyTestCase#assertTrue(java.lang.String, boolean), groovy.util.GroovyTestCase#assertTrue(boolean), groovy.util.GroovyTestCase#countTestCases(), groovy.util.GroovyTestCase#assertEquals(java.lang.String, short, short), groovy.util.GroovyTestCase#assertEquals(char, char), groovy.util.GroovyTestCase#assertEquals(java.lang.String, char, char), groovy.util.GroovyTestCase#assertEquals(byte, byte), groovy.util.GroovyTestCase#assertEquals(java.lang.String, byte, byte), groovy.util.GroovyTestCase#assertEquals(boolean, boolean), groovy.util.GroovyTestCase#assertEquals(int, int), groovy.util.GroovyTestCase#assertEquals(java.lang.String, int, int), groovy.util.GroovyTestCase#assertEquals(short, short), groovy.util.GroovyTestCase#assertEquals(java.lang.String, float, float, float), groovy.util.GroovyTestCase#assertEquals(double, double, double), groovy.util.GroovyTestCase#assertEquals(java.lang.String, java.lang.String, java.lang.String), groovy.util.GroovyTestCase#assertEquals(java.lang.String, double, double, double), groovy.util.GroovyTestCase#assertEquals(java.lang.String, boolean, boolean), groovy.util.GroovyTestCase#assertEquals(long, long), groovy.util.GroovyTestCase#assertEquals(java.lang.String, long, long), groovy.util.GroovyTestCase#assertEquals(float, float, float), groovy.util.GroovyTestCase#runBare(), groovy.util.GroovyTestCase#assertFalse(boolean), groovy.util.GroovyTestCase#assertFalse(java.lang.String, boolean), groovy.util.GroovyTestCase#assertNull(java.lang.Object), groovy.util.GroovyTestCase#assertNull(java.lang.String, java.lang.Object), groovy.util.GroovyTestCase#assertSame(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#assertSame(java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#assertNotSame(java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#assertNotSame(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#failSame(java.lang.String), groovy.util.GroovyTestCase#failNotSame(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#failNotEquals(java.lang.String, java.lang.Object, java.lang.Object), groovy.util.GroovyTestCase#wait(long, int), groovy.util.GroovyTestCase#wait(long), groovy.util.GroovyTestCase#wait(), groovy.util.GroovyTestCase#equals(java.lang.Object), groovy.util.GroovyTestCase#hashCode(), groovy.util.GroovyTestCase#getClass(), groovy.util.GroovyTestCase#notify(), groovy.util.GroovyTestCase#notifyAll() |
class junit.framework.TestCase |
junit.framework.TestCase#run(), junit.framework.TestCase#run(junit.framework.TestResult), junit.framework.TestCase#toString(), junit.framework.TestCase#getName(), junit.framework.TestCase#format(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#setName(java.lang.String), junit.framework.TestCase#fail(java.lang.String), junit.framework.TestCase#fail(), junit.framework.TestCase#assertNotNull(java.lang.String, java.lang.Object), junit.framework.TestCase#assertNotNull(java.lang.Object), junit.framework.TestCase#assertTrue(java.lang.String, boolean), junit.framework.TestCase#assertTrue(boolean), junit.framework.TestCase#countTestCases(), junit.framework.TestCase#assertEquals(java.lang.String, short, short), junit.framework.TestCase#assertEquals(char, char), junit.framework.TestCase#assertEquals(java.lang.String, char, char), junit.framework.TestCase#assertEquals(byte, byte), junit.framework.TestCase#assertEquals(java.lang.String, byte, byte), junit.framework.TestCase#assertEquals(boolean, boolean), junit.framework.TestCase#assertEquals(int, int), junit.framework.TestCase#assertEquals(java.lang.String, int, int), junit.framework.TestCase#assertEquals(short, short), junit.framework.TestCase#assertEquals(java.lang.String, float, float, float), junit.framework.TestCase#assertEquals(double, double, double), junit.framework.TestCase#assertEquals(java.lang.Object, java.lang.Object), junit.framework.TestCase#assertEquals(java.lang.String, java.lang.String), junit.framework.TestCase#assertEquals(java.lang.String, java.lang.String, java.lang.String), junit.framework.TestCase#assertEquals(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#assertEquals(java.lang.String, double, double, double), junit.framework.TestCase#assertEquals(java.lang.String, boolean, boolean), junit.framework.TestCase#assertEquals(long, long), junit.framework.TestCase#assertEquals(java.lang.String, long, long), junit.framework.TestCase#assertEquals(float, float, float), junit.framework.TestCase#runBare(), junit.framework.TestCase#assertFalse(boolean), junit.framework.TestCase#assertFalse(java.lang.String, boolean), junit.framework.TestCase#assertNull(java.lang.Object), junit.framework.TestCase#assertNull(java.lang.String, java.lang.Object), junit.framework.TestCase#assertSame(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#assertSame(java.lang.Object, java.lang.Object), junit.framework.TestCase#assertNotSame(java.lang.Object, java.lang.Object), junit.framework.TestCase#assertNotSame(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#failSame(java.lang.String), junit.framework.TestCase#failNotSame(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#failNotEquals(java.lang.String, java.lang.Object, java.lang.Object), junit.framework.TestCase#wait(long, int), junit.framework.TestCase#wait(long), junit.framework.TestCase#wait(), junit.framework.TestCase#equals(java.lang.Object), junit.framework.TestCase#hashCode(), junit.framework.TestCase#getClass(), junit.framework.TestCase#notify(), junit.framework.TestCase#notifyAll() |
Keeps track of the domain classes mocked within a single test so that the relationships can be configured for cascading validation.
Enables the cascading validation support for domain classes. This should be called after all the relevant domain classes have been mocked.
Loads the given codec, adding the "encodeAs...()" and "decode...()" methods to objects.
codecClass
- The codec to load, e.g. HTMLCodec.Mocks a controller class, providing implementations of standard methods like render and redirect
Mocks a domain class, providing working implementations of the standard dynamic methods. A list of domain instances can be provided as a source of data for the methods, in particular the queries.
domainClass
- The class to mock.instances
- An optional list of domain instances to use
as the data backing the dynamic methods.Creates a new Grails mock for the given class. Use it as you would use MockFor and StubFor.
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.Mocks the given class (either a domain class or a command object) so that a "validate()" method is added. This can then be used to test the constraints on the class.
Provides a mock implementation of the "log" property for the
given class. By default, debug and trace levels are ignored
but you can enable printing of debug statements via the
enableDebug
argument.
clazz
- The class to add the log method to.enableDebug
- An optional flag to switch on printing of
debug statements.Mocks a tag library, providing the common web properties as well as "out", "throwTagError()", and an implementation of the "render" tag.
Use this method when you plan to perform some meta-programming on a class. It ensures that any modifications you make will be cleared at the end of the test.
clazz
- The class to register.