This page discusses how to test Web Services using Groovy directly and in conjunction with WebTest and SoapUI.
Testing Web Services can be done in several ways. Here are three:
We are going to use the Web Service example at:
You can be a normal client web service client and perform asserts on the returned results:
Using the WebTest variations makes sense if you are combining your tests into an acceptance test suite.
Here is how you would test it using traditional WebTest:
Where addreq.xml would look something like:
and squarereq.xml would look something like:
Alternatively, testing using groovy within WebTest would look like:
Note: you will need to place the jars mentioned on that page in your webtest lib directory (i.e. groovysoap, stax, jaf and mail jars) when using this variation.
The first approach (traditional webtest) produces more information in the test summary reporting but requires you to do more work (i.e. keep the requests around as XML). It depends if you already have those XML files around for other purposes, e.g. manual testing.