A unit testing mixing that add behavior to support the testing of tag libraries and GSP pages. Can be used in combination with DomainClassUnitTestMixin to support the testing of tag libraries and GSPs
Views and templates can be mocked via the ControllerUnitTestMixin.groovyPages map where the keys are the names of the pages and the values are the contents of the GSP page
Alternatively, within a Grails project the unit test will fallback to loading views and templates from grails-app/views
For mocking tag libraries the GroovyPageUnitTestMixin.mockTagLib method allows you
to mock custom tag libraries. There is no need to mock core tag libraries like
Constructor and description |
---|
GroovyPageUnitTestMixin
(java.util.Set<java.lang.String> features) |
GroovyPageUnitTestMixin
() |
Type Params | Return Type | Name and description |
---|---|---|
|
java.lang.String |
applyTemplate(java.lang.String contents, java.util.Map model = [:]) Renders a template for the given contents and model |
|
protected void |
applyTemplate(java.io.StringWriter sw, java.lang.Object template, java.lang.Object params = [:]) |
|
void |
assertOutputEquals(java.lang.Object expected, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString() Asserts the output of a given template against the specified expected value. |
|
void |
assertOutputMatches(java.lang.Object regex, java.lang.Object template, java.lang.Object params = [:], groovy.lang.Closure transform = { it.toString() Asserts the output of a given template against the specified regex. |
|
java.lang.Object |
mockTagLib(java.lang.Class tagLibClass) Mocks a tag library, making it available to subsequent calls to controllers mocked via mockController(Class) and GSPs rendered via applyTemplate(String, Map) |
|
java.lang.String |
render(java.util.Map args) Mimics the behavior of the render method in controllers but returns the rendered contents directly |
Methods inherited from class | Name |
---|---|
class ControllerUnitTestMixin |
createAndEnhance, getFlash, getGroovyPages, getModel, getParams, getRequest, getResponse, getServletContext, getSession, getStatus, getView, getViews, getWebRequest, mockCommandObject, mockController, testFor |
class GrailsUnitTestMixin |
defineBeans, getApplicationContext, getConfig, getGrailsApplication, getMainContext, getMessageSource, mockCodec, mockFor, mockForConstraintsTests, shouldFail, shouldFail |
class TestMixinRuntimeSupport |
getFeatures, getRuntime, setRuntime, setTestClass |
class groovy.lang.GroovyObjectSupport |
groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll() |
Renders a template for the given contents and model
contents
- The contentsmodel
- The modelAsserts the output of a given template against the specified expected value.
expected
- The expected outputtemplate
- A snippet of GSPparams
- An optional parameter that allows variables to be placed in the binding of the GSPtransform
- An optional parameter that allows the specification of a closure to transform the passed StringWriterAsserts the output of a given template against the specified regex.
expected
- The regex expression expected to match the outputtemplate
- A snippet of GSPparams
- An optional parameter that allows variables to be placed in the binding of the GSPtransform
- An optional parameter that allows the specification of a closure to transform the passed StringWriterMocks a tag library, making it available to subsequent calls to controllers mocked via mockController(Class) and GSPs rendered via applyTemplate(String, Map)
tagLibClass
- The tag library classMimics the behavior of the render method in controllers but returns the rendered contents directly
args
- The same arguments as the controller render method accepts