6 Implementing consumer-driven provider contract tests

 

This chapter covers

  • Guidelines in writing consumer-driven provider contract tests
  • Contract testing tooling setup for the provider
  • Provider contract tests between a web application and a data provider
  • Provider contract tests between a mobile app and a data provider

In chapters 4 and 5 of this book, our primary focus was on creating the contract tests designed for various consumers. It’s essential to keep in mind that in contract testing, there are two sets of tests that you need to write—one set encompassing consumers and the other encompassing providers. Based on our practical experience, we found that when it comes to setting up provider contract tests, this phase typically demands less code than its counterpart, the consumer contract tests.

Within the scope of consumer-driven contract testing (CDCT), we observed that most of the contract testing efforts belong to the consumer teams. After all, it’s the consumer teams that essentially lay down the terms of the contract that providers must adhere to. Nevertheless, this shouldn’t devalue the significance of provider tests. In fact, provider tests hold equal weight in contract testing. Without properly executed provider tests, the contract testing life cycle can’t function as intended.

6.1 Guidelines in writing provider contract tests

6.1.1 The focus of a provider contract test

6.1.2 Using provider states effectively

6.1.3 Using can-i-deploy to verify that you can safely deploy to production

6.2 Contract testing tooling setup for the provider

6.3 Provider contract tests between a web application and data provider

6.3.1 Writing the provider test

6.3.2 Introducing provider states

6.4 Provider contract tests between a mobile app and data provider

6.5 Chapter exercise

Summary