Grails controller integration testing


I wanted to test a groovy controller using a unit test. We had a render whose arguments needs to be verified. Initially we added a test case which extends ControllerUnitTestCase and tried a lot using the renderArgs that is given by the Unit test case. We were able to find that the redirectArgs were working properly but the renderArgs was returning null.

After a bit of struggle, we found that the render arguments are only available in a spring modelandview class which gets constructed when u call render.

Finally, when we changed to the following code

controller.modelAndView.viewName
controller.modelAndView.model

everything started to work.

Even though it is documented in the grails doc in a completely different section in grails doc. The section on testing seems to be misleading.

Advertisements

One thought on “Grails controller integration testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s