Consumer Driven Contract testing
Jaroslav Holaň, Zonky
jOpenSpace 2017
Design by contract
Pact.io
Spring Cloud Contract
Pact.io
Spring Cloud Contract
User Service
Admin Service
request
response
User Service
Admin Service
request
response
Contract
request
response
Provider
Consumer
pact file
{
"provider": {
"name": "User Service"
},
"consumer": {
"name": "Admin Service"
},
"interactions": [
{
"description": "The request for the count of users.",
"request": {
"method": "GET",
"path": "/users/count"
},
"response": {
"status": 200,
"body": {
"count": 100
}
} } ] }
pact file
file system
URL
Pact broker
Pact broker service
Mock server
docker start pact-jvm-server
POST http://localhost:9999/create
{
"provider": {
"name": "User Service"
},
"consumer": {
"name": "Admin Service"
},...}
{
"port": 20007
}
�GET http://localhost:20007/users/count
Test consumer
@Test�public void whenCallProvider_returnValidMessage() {� ConsumerService consumer = createConsumer();� String response = consumer.callProvider();� assertEquals("Hello from service two", response);�}
org.junit.ComparisonFailure:�Expected :Hello from service two�Actual :Hello from service 2
Test provider
docs.pact.io
�JaroslavHolaň
Software Magician at