Grey-Bearded Geek

Random Thoughts Of A Middle-Aged Software Engineer

Testing Grails Controllers with Spock Part 2

May 19th 2011

My previous post showed how to get around some of the shortcomings of testing Grails Controllers with the ControllerSpec provided by the Spock testing framework.

I also found that ControllerSpec is a subclass of UnitSpec, so it does not provide transactional rollback. This makes ControllerSpec somewhat undesirable for an integration test.

So, I merged the code for ControllerSpec and IntegrationSpec to create ControllerIntegrationSpec. It works just like ControllerSpec, but executes each test method in a transaction, and rolls the transaction back at the end of the method.

Here is the Groovy source, which can also be found at https://github.com/rfreedman/spock-integration-controller-spec/

blog comments powered by Disqus
Categories: Chariot, Java, Groovy, Grails