The test automation pyramid suggests that we should favour unit and integration tests over end-to-end tests, which leads developers to use test doubles (fakes, stubs, mocks etc.). The risk is that the developer's test double does not behave in exactly the same way as the actual component that it is replacing. When this happens, the tests all pass in your build pipeline, but you get failures when it's released into an integration (or production) environment.
Contract testing is a technique that can give you confidence that your test doubles are accurately simulating the dependencies that they replace. This is not a new technique, but the extra investment in creating and maintaining (yet another) suite of tests has restricted its uptake. Instead, organizations mitigate the risks by investing in more and more integration environments and end-to-end tests. This was always expensive, but with the adoption of micro-service architectures across the industry, the cost and complexity has escalated to a point where this approach is no longer sustainable.
There is now an urgent need for organizations to revisit contract testing, with a specific focus on consumer driven contracts for micro-services. This need led to the creation of the Pact open source tool for HTTP based micro-services. The Pact project has created a multi-platform suite of tools that dramatically simplifies the adoption of contract testing.
In this session, you'll learn why contract testing is critically important, look at how you can incorporate contract testing in your development practices, and get an introduction to Pact.
9. @sebrose h)p://smartbear.com
Design by contractDesign by contract
Contract
• an agreement between client
and supplier
Characteris3cs
• expect some benefits
• incur some obliga3ons
24. @sebrose h)p://smartbear.com
• Pass in a valid customer ID, return a decimal
value
• Can we say anything about the magnitude
of the returned value?
• Pass in an invalid customer ID…. then what?
What’s our implicit contract?
30. @sebrose h)p://smartbear.com
▪Closed and complete Provider contracts express a service's business
function capabilities in terms of the complete set of exportable elements
available to consumers, and as such are closed and complete with respect
to the functionality available to the system.
▪Singular and authoritative Provider contracts are singular and authoritative
in their expression of the business functionality available to the system.
▪Bounded stability and immutability A provider contract is stable and
immutable for a bounded period and/or locale. Provider contracts typically
use some form of versioning to differentiate differently bounded instances
of the contract.
https://martinfowler.com/articles/consumerDrivenContracts.html
Provider contracts
31. @sebrose h)p://smartbear.com
▪Open and incomplete Consumer contracts are open and incomplete with
respect to the business functionality available to the system. They express
a subset of the system's business function capabilities in terms of the
consumer's expectations of the provider contract.
▪Multiple and non-authoritative Consumer contracts are multiple in
proportion to the number of consumers of a service, and each is non-
authoritative with regard to the total set of contractual obligations placed on
the provider. Consumers may evolve at different rates.
▪Bounded stability and immutability Like provider contracts, consumer
contracts are valid for a particular period of time and/or location.
https://martinfowler.com/articles/consumerDrivenContracts.html
Consumer driven contracts (CDC)
40. @sebrose h)p://smartbear.com
Pact provides a mechanism for crea3ng a
contract between a service consumer and a
service provider, and then providing the tools
to validate that the consumer and provider
adhere to the contact independently of each
other.
https://dius.com.au/2014/05/19/simplifying-micro-service-testing-with-pacts/
Simplifying micro-service tes.ng
51. @sebrose h)p://smartbear.com
• Pacts are published by Consumer
• Pacts are fetched by Provider
• Results are stored in the “Matrix”
• “Matrix” supports independent deployment
Pact broker - key points