- Pact is a consumer-driven contract testing framework. Born out of a microservices boom, Pact was created to solve the problem of integration testing large, distributed systems. (Old definition)
- How Pact works slide from pactflow.io
- ✅ Rescue for integration test cost.
- ✅ Gives fast feedback
- ✅ Implement any programming language you want. For example
- ✅ No dedicated test environments (it works on dev machine)
Interaction: A request and response pair. A pact consists of a collection of interactions.
Pact file: A file containing the JSON serialised interactions (requests and responses) that were defined in the consumer tests. This is the Contract.
Pact verification: To verify a Pact contract, the requests contained in a Pact file are replayed against the provider code, and the responses returned are checked to ensure they match those expected in the Pact file.
Pact Specification A provider state name is specified when writing the consumer specs, then, when the pact verification is set up in the provider the same name will be used to identify the set up code block that should be run before the request is executed.
The Pact Broker is an open source tool that requires you to deploy, administer and host yourself. It enables you to share your pacts and verification results between projects
dsl.Like(content)
tells Pact that value is not important, just focus type match.
dsl.EachLike(content, min)
tells Pact that the value should be array type, consisting of elements like those passed
in. min
must be >= 1.
"fabrics": dsl.EachLike(dsl.MapMatcher{
"title": dsl.Like("Pamuk"),
"count": dsl.Integer()
}, 1),
dsl.Term(example, matcher)
tells Pact that the value should match using a given regular expression, using example in
mock responses.
"type": Term("admin", "admin|user|guest")
=> "type": "admin"
method | description |
---|---|
Identifier() |
Match an ID (e.g. 42) |
Integer() |
Match all numbers that are integers (both ints and longs) |
Decimal() |
Match all real numbers (floating point and decimal) |
HexValue() |
Match all hexadecimal encoded strings |
Date() |
Match string containing basic ISO8601 dates (e.g. 2016-01-01) |
Timestamp() |
Match a string containing an RFC3339 formatted timestapm (e.g. Mon, 31 Oct 2016 15:21:41 -0400) |
Time() |
Match string containing times in ISO date format (e.g. T22:44:30.652Z) |
IPv4Address() |
Match string containing IP4 formatted address |
IPv6Address() |
Match string containing IP6 formatted address |
UUID() |
Match strings containing UUIDs |
Pact Docs
Pact Go
Turkish Microservice Architecture Book
Pact Broker Docker
Building Microservices
Contract testing and how Pact works
Test Double
Difference between gobuild and build directive