How do I test this:
render view: "create", model: [user: user]
I know how to test redirectArgs and stuff, but I can't find an example to test something like this. It seems like articles and stuff go out of their way to not test this....
How do I test this:
render view: "create", model: [user: user]
I know how to test redirectArgs and stuff, but I can't find an example to test something like this. It seems like articles and stuff go out of their way to not test this....
renderArgs
is what you want. (From ControllerUnitTestCase
)
E.g to test that the correct view will be rendered
assertEquals 'create', renderArgs.view
Check the model
assertEquals user, renderArgs.model.user
Make sure that your test extends ControllerUnitTestCase
Etc etc
Are you sure this works? I'm trying the incredibly trivial test below which does not work:
NotebookController:
def index = {
log.info("redirecting to list")
redirect(action: "list", params: params)
}
NotebookControllerTest
package net.codezilla.knodebook import grails.test.*
class NotebookControllerTests extends ControllerUnitTestCase { protected void setUp() { super.setUp() }
protected void tearDown() {
super.tearDown()
}
void testIndex() {
controller.index()
assertEquals "/notebook/list", renderArgs.view
}
}
Running this test gives the following result:
testIndex Failure junit.framework.ComparisonFailure: null expected: but was:
junit.framework.AssertionFailedError: junit.framework.ComparisonFailure: null expected: but was: at net.codezilla.knodebook.NotebookControllerTests.testIndex(NotebookControllerTests.groovy:24)