This is a sample barebone contract testing framework, having both Dummy Consumers & a Dummy Provider.
-
Start docker in the machine. Install docker in your machine from here if you dont have it.
-
Navigate to the root folder level of the cloned repository and bring up the pact broker in docker using below command.
docker-compose up
P.S: If above command did not work, try running
docker-compose pull
and thendocker-compose up
The docker compose file pulls the pact-broker image and also spawns up the prostgres DB which is used by pact-broker to store data. Dive into the compose file for more understanding.
-
If every thing goes well, you should be able to access the pact broker UI at http://localhost:9292
- We have two consumers and one provider for the setup. (There are actually three different projects. I have pushed then into a single repo for ease of cloning.)
- Import the
consumer_one
,consumer_two
andprovider_one
into three different instances of your IDE respectively.
-
Open
consumer_one
in IDE. -
Execute the gradle task to run the contract tests of
consumer_one
with below command../gradlew contractTest
If everything goes well, the test runs successfully and you should be able to see a pact json file in 'build>pacts>consumer_two-provider_one.json'
-
Execute the gradle task to publish this pact to the pact-broker running in docker with below command.
./gradlew pactPublish
-
Go to the pact-broker UI (link in the Setting up pack broker above) and you should be able to see the pact of consumer_one in this UI
- Repeat the same process as mentioned for consumer_one.
-
Open
provider_one
in IDE. -
Execute the gradle task to verify the contracts from the pact-broker with below command.
./gradlew contractTest
This task will verify the pacts of both the consumers published in pact-broker.
-
For the current setup, all the tests should come out green.