Reputation: 2322
I have the following controller:
class MyController {
def simple = {
render "simple"
}
}
An respectively the following test case:
class MyControllerTests extends ControllerUnitTestCase {
void testSimple() {
controller.simple
def body = controller.response.contentAsString
assertEquals "simple", body
}
}
I would have expected this test to pass successfully. Surprisingly, it fails with the following result:
junit.framework.ComparisonFailure: null expected:<[simple]> but was:<[]>
I have run the application through the browser and works as expected (i.e. prints "simple).
What am i missing here?
Upvotes: 0
Views: 845
Reputation: 535
Hi I think your test should look like this:
void testSimple() {
controller.simple()
def body = controller.response.contentAsString
assertEquals "simple", body
}
You need to call the simple action(closure).
See here for more: http://www.gitshah.com/2010/04/unit-testing-grails-controller-part-1.html
Thanks,
Jim.
Upvotes: 3