0
votes

We'd like to add some integration tests for the many REST services that our Grails app exposes, instead of manually verifying them using the Firefox Poster plugin that we are currently using.

BTW, In our case it HAS to be an integration test, not a unit test.

I trust others have gone thru' this before and could save us some time instead of experimenting...

`grails test-app -integration`

Does the above command actually launch the functionality required to do a self-post to our own app (http://localhost/myapp) ? It would have to go through the url mapping pipeline, xml content negotiation, spring/acegi security, etc. If so, I suppose we could use the Groovy RESTClient as documented here: http://groovy.codehaus.org/modules/http-builder/doc/rest.html

Google tells me another option is the functional-testing plugin: http://thediscoblog.com/2009/06/15/grails-hip-tip-testing-restful-services/

Any comments or issues from the experienced? It's a Grails 1.2.1 app using plugins.acegi=0.5.2

2

2 Answers

0
votes
0
votes

The REST services are usually created via actions in a controller that are set in the URLMappings to work with the different HTTP methods (GET, PUT, POST, DELETE), so since they are simple actions in a controller an integration test can be just a test method that test the action like any other, sending them the content-type you need, JSON for example and passing the correct data as JSON if that is what your services is expecting.

You can create multiple test methods for the same action to test the difference responses, for example if a non valid resource is requested than test that the service is returning the correct error code 404 for instance.