TESTING
Sai Krishna
Lead Consultant
ThoughtWorks
Srinivasan Sekar
Lead Consultant
ThoughtWorks
Payment
Users
{
"user":[]
}
{
"users":[]
}
Test Pyramid
Payment Service
Mocked User service
Request
Response
Targeted
Cheap
Fast
Not Trustworthy
TrustWorthy
Slow
Brittle
Whose fault ?
The idea of Consumer-Driven Contracts is to formalize the interactions between a consumer and a provider.
Consumer creates a contract, which is an agreement between the consumer and a provider on the interactions that will take place between them.
Provider has agreed on the contract, both consumer and provider can take a copy of the contract and use tests to verify that their corresponding implementations don’t violate the contract. The advantage of these new tests is that they are pretty much unit-tests: they can be run locally and independently, and they are fast and reliable
A contract between a consumer and provider is called a pact. Each pact is a collection of interactions. Each interaction describes:
CONSUMER
API
PRODUCER MOCK
API
Request
Response
Contract
PRODUCER VERIFIER
PRODUCER
API
Request
Response
Contract
{
"user":
}
{
"users":
}
By formalising the interaction between consumer and provider, and verifying that both services stick to the contract they’ve agreed upon, we see that we have no need to perform integration tests between them. Instead we’re using new tests that are specific, fast and robust.
Blog Summary