Testing response compliance using JSON schemas
Do you have REST responses that you'd like to validate against a JSON schema? This recipe shows a simple way to do this using a Groovy
TestStep.
Getting ready
First, we're going to need a simple test project with a mock that produces some sample JSON responses for us to validate. A ready-made project invoice-rest-json-schema-soapui-project.xml
has been provided to do this in the chapter 4 samples. It contains a simple REST project with one resource GET /invoice/{id}
, a mock with two sample responses, and a test case with REST
TestRequest and Groovy
TestSteps. The invoice document is the usual example; that is:
{"invoice": { "id": 12345, "companyName": "Test Company", "amount": 100 }}
We'll also need a JSON schema to validate this, invoice_schema.json
has been provided in the chapter 4
samples:
{ "$schema":"http://json-schema.org/draft-03/schema", "required":true, "type":"object", "properties":{ "invoice":{ ...