Testing Web Services can be done in several ways. Here are three:
- act like a normal web services client and perform asserts on the returned result
- use WebTest (with either the XML or Groovy syntax)
- use SoapUI (for functional testing)
We are going to use the Web Service example at:
Being a client
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.