2. Hi 👋🏼
I’m Gaurav Singh 🏼🏼
Test automation 🏼 at Gojek, Bangalore
Full stack tester …. (mobile 📱, web 🏼, backend 🏼)
Find me on below:
• https://automationhacks.blog/
• https://www.linkedin.com/in/automationhacks/
• https://twitter.com/automationhacks
• https://github.com/gaurav-singh
• https://stackoverflow.com/users/5336432/gaurav-singh
3. Learning goals
• What is consumer driven contract testing?
• What problems does it solve over integration tests?
• Understand it’s nuts and bolts ⚙️
• Implement a contract test for a twitter like API using PACT
framework with JVM
• When not to use? 🏼
6. Consumer driven contracts 🏼
• Confirms contract between a consumer and provider (called
Pact) 📃
• Written from the consumer’s perspective 📲 🏼 🌍
• Allows testing them in isolation
• Supports testing HTTP, message queues
7. Example AUT: Twitter API
Select “Run in postman” to import the collection in desktop client
8. Let’s run through a test scenario
• Login as a user and get login token
11. But first a bit of terminology 😇
• Consumer
• Provider
• Contract
• Interaction
• Broker
12. Consumer
• Any component that initiates an HTTP request to a provider
• Some Examples:
• Web or mobile app frontend
• Another service
• Desktop Client
13. Provider
• Component that responds to the HTTP request
• Might have multiple HTTP endpoints as part of the micro-service
(CRUD operations)
• A single deployable unit
17. Tests consumer first
• Checks if consumer generates correct request
• Checks if it can handle the different responses from the mock
provider
18. Test provider
• Driven entirely by PACT framework
• Sends actual request to provider
• Compare the actual response to minimum expected response
(described in interaction)
20. If all you have a hammer…
• Dos
• Check minimal shared understanding of what the provider should
return to us.
• Works best if you/your org/partner org are developing the consumer
and provider
• Dont’s
• Write to substitute all functional integration tests (don’t check side-
effects)
• Use it for performance and load testing
• To Test Pass through APIs
1. Using the Pact DSL, the expected request and response are registered with the mock service.
2. The consumer test code fires a real request to a mock provider (created by the Pact framework).
3. The mock provider compares the actual request with the expected request, and emits the expected response if the comparison is successful.
4. The consumer test code confirms that the response was correctly understood