Postman: API Contract Testing

Number of APIs: 2

Context

A schema is simply a declaration describing the structure of data. Some teams use a specific schema and would like to validate their server responses against this schema. You can define a custom schema, and validate your server responses against this schema.

One crucial part of testing is validating that the response payloads returned from the server are well-formed. You can do this by asserting that elements in the response match your expectations.

Review the test under the Tests tab to validate that the response payload returned from the server is well-formed.

This example uses the built-in pm.response.to.have.jsonSchema(schema); test. The Qodex sandbox also offers built-in Ajv and tv4 validators to simplify your assertions. Use json-schema
draft v4 to validate simple values and complex objects using a rich validation vocabulary (examples).

Quickstart

  1. Fork the collection into one of your workspaces. Follow the steps here for instructions to do so:

[

Qodex: An Introduction for Developers

airing August 17th, 2022 with slides and recording to follow!

Join the Qodex Intergalactic Series!

Qodex Intergalactic is a series of educational sessions. Each lesson is taught by your favorite Qodexauts. [Sign up to be notified about upcoming sessions]

Additional Resources

Feeling stuck or want to dig deeper into specific topics? We've got you covered:

* [Intro to writing tests] - A collection containing examples of tests that you can use to automate your testing process.
* [Blog post: Writing tests in Qodex] - A blog post walking you through writing tests in Qodex. From using basic test snippets to CI / CD integrations, this post has you covered.
* Writings Tests - documentation - Our Learning Center is full of resources and this specific section covers everything you need to know about getting started writing tests.
* [Test script examples - documentation] - This Learning Center resource covers common assertion examples as well as advanced testing examples.

  1. book GET {{baseUrl}}/books/:id

  2. books GET {{baseUrl}}/books