4 Implementing consumer-driven contract testing for web applications

 

This chapter covers

  • Guidelines in writing consumer contract tests
  • Contract testing tooling setup for the consumer
  • Writing consumer contract tests between a web application and data provider
  • Publishing contracts to a Pact Broker

At this point, we hope you’re itching to start writing your first contract test! As mentioned in chapter 2, it’s always better to start with the “Why” and to understand what pain points contract testing is trying to solve before you rush in to try it out just because someone told you to. Building on the Why, it’s essential to have a solid understanding of the core concepts and principles of contract testing. If you feel that you want to read the previous chapters again to solidify your knowledge further, please go ahead. We’d rather you make sure you fully understand how contract testing works before trying out the implementation part.

4.1 Guidelines in writing consumer contract tests

4.1.1 The focus of a consumer contract test

4.1.2 The importance of using mocks instead of stubs

4.1.3 Using loose matchers to avoid high coupling

4.1.4 The importance of writing isolated contract tests

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

4.2 Contract testing tooling setup for the consumer

4.2.1 Requirements

4.3 Consumer contract tests between a web application and data provider

4.3.1 Movies API overview

4.3.2 Web application overview

4.3.3 Consumer contract

4.3.4 Writing the first consumer contract test

4.3.5 Other programming languages

4.4 Publishing the contract to Pact Broker

4.4.1 Committing all changes to GitHub

Summary