Skip to content

How to create a Contract test

How to contract test

In this how to guide you will learn how to create, deploy, and run a contract test for a Platform service (Web App, User Interface etc) for your team.

Prerequisites

Before adding tests for your service, you will need to ensure that:

Overview

By completing this guide, you will have completed these actions:

  • Learned how to add a contract test for your service.
  • Learned how to run a contract test locally.
  • How to customize your pipeline to run contract tests for different env.

Guide

Note

Every pipeline run includes steps to run varoious tests pre deployment and post deployment. These tests may include unit, integration, acceptance, performance, accessibilty etc as long as they are defined for the service.

The pipeline will check for the existence of the file ./docker-compose.contract.test.yaml to determine if contract tests have been defined.

How to add a contract test for your service?

The contract Test scripts should be added to the test\contract folder in the GitHub repository of the service. Refer to the ffc-demo-web example. This folder should contain *.test.js files which are required to execute the tests. Tests will be run using PACT BROKER service.

Requirments for local development

  • Docker Desktop 2.2.0.3 (42716) or higher

How to run a contract test locally?

Executre the above commands in bash or PowerShell

# this will execute the docker-compose at the root folder to create an instance of the service and its dependences
docker-compose -f docker-compose.yaml -f docker-compose.contract.test.yaml -p "<<servicename>>-test" up

How to parameterising your Tests

Set required PACT Broker credentials to run tests

1
2
3
  export PACT_BROKER_URL="PACT Broker URL"
  export PACT_BROKER_USERNAME="PACT Broker username"
  export PACT_BROKER_PASSWORD="PACT Broker password"

How to customize your pipeline to run contract tests?

You can customize the environments where you would like to run contract test (within the pipeline it is referred as integration test)

1
2
3
4
5
postDeployTest:
  envToTest: snd4
  testEnvs:
    integrationTests: snd4
  testsToRun: 'contract'

Please refer ffc-demo-web pipeline:

How to disable test?

if you want to disable the test for any reason please refer Disable Test