The document discusses implementing a scalable testing strategy for microservices using consumer-driven contract tests. It describes the testing pyramid concept of grouping tests into unit, integration, and acceptance categories. Consumer-driven contract tests involve defining interactions and behaviors in unit tests on both the consumer and provider sides. The document recommends the Pact tool for generating contracts from code and providing provider verification. It provides examples of implementing consumer-driven contract tests on both the consumer and provider sides and references additional resources on the topic.
2. Consumer-Driven Contract Tests
ping@kloia.com
The testing pyramid is a concept that
groups software tests into three
different categories. This helps
developers and QA professionals
ensure higher quality, reduce the
time it takes to find the root cause of
bugs, and build a more reliable test
suite.
4. Consumer-Driven Contract Tests
ping@kloia.com
Great for developing and testing intra-organisation microservices.
● You (or your team/organisation/partner organisation) control the development of both the
consumer and the provider.
● The requirements of the consumer(s) are going to be used to drive the features of the
provider.
● There is a small enough number of consumers for a given provider that the provider team
can manage an individual relationship with each consumer team.
5. Integration Tests vs Contract Tests
ping@kloia.com
Speed
Maintenance
Reliability
Realizing bugs towards the end of
deployment
Scalability
6. Pact
ping@kloia.com
● Some of the tools that support Consumer-Driven Contract Testing are Pact and Spring Cloud
Contract.
● We chose Pact because:
○ Generation of contracts from the code
○ Provider verification (pact-jvm-provider-junit)
○ Supports multiple languages JVM, Node, JS web apps, …
○ Pact Specification
○ Pact Broker
7. Pact Broker
ping@kloia.com
● Helps managing, versioning and distributing
contracts.
● Great tool to visualize contracts and system
relationships (dependency graph).
● Contracts as a form of “Live Documentation”
for APIs and interactions between
components.
13. Pact uses the state description on the contract to
determine which set-up logic needs to be
executed before running a generated test.
Contract Testing on the Provider Side
ping@kloia.com
16. ● Implementing Consumer-Driven Contract tests in Angular, Paulo Clavijo
https://paucls.wordpress.com/2017/08/04/pact-consumer-driven-contract-imple
mentation-in-angular
● Configure Pact JS Consumer Contract tests in Angular, Paulo Clavijo
https://paucls.wordpress.com/2017/08/04/configure-pact-js-consumer-contract-
tests-in-angular
● Sample project on Provider Side https://github.com/paucls/task_list_api-kotlin-pact
Further Reading
ping@kloia.com
17. References
● ContractTest, Martin Fowler. https://martinfowler.com/bliki/ContractTest.html
● Pact documentation https://docs.pact.io/documentation/implementation_guides.html
● Testing Strategies in a Microservice Architecture, Toby Clemson
https://martinfowler.com/articles/microservice-testing/
● Integrated Tests Are A Scam, J.B. Rainsberger http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam
● Consumer-Driven Contracts: A Service Evolution Pattern, Ian Robinson
https://www.martinfowler.com/articles/consumerDrivenContracts.html
● Microservices, Flexible Software Architecture. Eberhard Wolff.
● Contract testing with GraphQL, Andreas Marek
https://www.andimarek.com/post/contract-testing-graphql
● https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit