Support class for writing unit tests for controllers. Its main job is to mock the various properties and methods that Grails injects into controllers. By default it determines what controller to mock based on the name of the test, but this can be overridden by one of the constructors.
Modifiers | Name | Description |
---|---|---|
protected java.lang.Object |
controller |
Fields inherited from class | Fields |
---|---|
class MvcUnitTestCase |
forwardArgs, mockFlash, mockParams, mockRequest, mockResponse, mockSession, redirectArgs, renderArgs, webRequest |
class groovy.util.GroovyTestCase |
TEST_SCRIPT_NAME_PREFIX |
Constructor and description |
---|
ControllerUnitTestCase
() Creates a new test case for the controller that is in the same package as the test case and has the same prefix before "Controller" in its name. |
ControllerUnitTestCase
(java.lang.Class controllerClass) Creates a new test case for the given controller class. |
Type | Name and description |
---|---|
java.lang.Class |
getControllerClass() |
protected java.lang.Object |
mockCommandObject(java.lang.Class clazz) Mocks a command object class, providing a "validate()" method and access to the "errors" property. |
protected java.lang.Object |
newInstance() |
protected void |
setUp() |
protected void |
setXmlRequestContent(java.lang.String content) Sets an XML string as the body of the mock HTTP request. |
protected void |
setXmlRequestContent(java.lang.String encoding, java.lang.String content) Sets an XML string as the body of the mock HTTP request. |
protected void |
setXmlRequestContent(groovy.lang.Closure c) Sets the body of the mock HTTP request to some XML. |
protected void |
setXmlRequestContent(java.lang.String encoding, groovy.lang.Closure c) Sets the body of the mock HTTP request to some XML. |
Methods inherited from class | Name |
---|---|
class MvcUnitTestCase |
bindMockWebRequest, getTestClass, newInstance, reset, tearDown |
class GrailsUnitTestCase |
addConverters, enableCascadingValidation, loadCodec, mockConfig, mockController, mockDomain, mockFor, mockForConstraintsTests, mockLogging, mockTagLib, registerMetaClass, setUp, tearDown |
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#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#countTestCases(), 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() |
Creates a new test case for the controller that is in the same
package as the test case and has the same prefix before "Controller"
in its name. For example, if the class name of the test were
org.example.TestControllerTests
, this constructor
would mock org.example.TestController
.
Creates a new test case for the given controller class.
Mocks a command object class, providing a "validate()" method and access to the "errors" property.
Sets an XML string as the body of the mock HTTP request. The string is converted to bytes based on a UTF-8 encoding.
Sets an XML string as the body of the mock HTTP request. The given string is converted to bytes according to the given encoding.
Sets the body of the mock HTTP request to some XML. The XML is provided as an XmlBuilder-compliant closure. The XML is encoded to bytes using UTF-8.
Sets the body of the mock HTTP request to some XML. The XML is provided as an XmlBuilder-compliant closure. The XML is encoded to bytes using the specified encoding.