Skip to content

jocrah/contract-testing-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contract-testing-demo

A Consumer-Driven Contract Testing Demo

This is a simple setup to demonstrate how services can interact with a minimal expectation of breaking in production due to inevitable changes in a service which is being depended upon

This is done using the pact library

For simplicity, the project has the following services:

  1. client (consumer)
  2. api (provider)

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes

Prerequisites

  1. Install Node and NPM
  2. Install Docker

Steps for setting up project

  1. Check the settings in the docker-compose.yml file and run docker-compose up -d in root folder

This is to get a working mysql server running and also to start up the pact broker

  1. Make sure to create a local database for the pacts to be stored in and reconfigure the environment for the pact broker in the docker-compose.yml file if need be

Let's go on a tour

Consumer-Driven Contract Testing Flow

Similar to the workflow of your usual consumer-driven contract tested application, we follow these steps

  1. First run the consumer test, npm run test:consumer

With this action, the necessary pacts are created and stored in a newly created pacts folder

  1. For local testing purposes, publish the generated pacts if everything checks out by running npm run publish-pacts.

NB: Unfortunately this is a Linux specific command in relation to sh and will be addressed soon.

  1. Check the broker base url (localhost:9092) and see the pacts successfully published in a simple ui

Published pact

  1. Now we focus on our movie api which serves as our provider. We run npm run test:provider. This, if it passes, verifies the pact/contract and this can also be confirmed in the broker ui served on localhost:9092

pact2

  1. To better appreciate this, tweak the response from the api and see as the provider test fails due to difference in expectation between what the contract expects and what the api is returning

About

A Consumer-Driven Contract Testing Demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published