11 Implementing provider-driven contract testing

 

This chapter covers

  • Introduction to provider-driven contract testing
  • Implementing consumer test adapters
  • Implementing provider tests with API testing tools

As mentioned in chapter 1, section 1.4, consumer-driven contract testing (CDCT) is when the consumer creates the contract and shares it with the data providers, essentially driving the requirements. The consumer-driven approach aims to avoid over-engineering from the provider side by only providing the data the consumer needs. Throughout chapter 2, we provide the benefits of adopting CDCT, and, in chapter 6, we talk about provider tests that verify consumer contracts. However, we also mentioned that the CDCT approach only works with good team communication and buy-in, and there could be scenarios where teams can’t adopt this approach.

For instance, imagine that in the web consumer example used in chapter 1, the consumer has decided to use a third-party data provider who provides random images of dogs, as shown in figure 11.1.

11.1 Introduction to provider-driven contract testing

11.1.1 Why was PDCT introduced?

11.1.2 How PDCT addresses the drawbacks of CDCT

11.1.3 Drawbacks with PDCT

11.2 Implementing consumer test adapters

11.2.1 Cypress consumer adapter

11.2.2 WireMock consumer adapter

11.2.3 Publish consumer contracts

11.3 Implementing provider tests with API testing tools

11.3.1 Postman and OpenAPI example

11.3.2 Dredd and OpenAPI example

11.3.3 Publish provider API specification and test results

11.3.4 Checking consumer contracts

Summary