This project is written to attempt to understand more about Consumer Driven Contract
with the use of Spring Boot + Pact / Spring Cloud Contract
- Basic understanding and setup of Pact consumer / provider
- Basic understanding and setup of Pact server
- Basic understanding and setup of SCC provider / consumer
- HTTP contract test for Pact
- Messaging contract test for Pact
- HTTP contract test for SCC
- Messaging contract test for SCC
- Using SCC with Pact Broker
This repository includes four distinct sub-project;
-
- Provides two API
- GET /profiles
- GET /profiles/{id}
- Provides two API
Navigate to the individual directory and run
./gradlew bootRun
Navigate to the individual directory and run
./gradlew [clean] build
As mentioned earlier, without using Broker
, we need to transfer the generated contract from the Consumer
to Provider
manually. However, with Broker
, we can simply ask the Consumer
to publish the contracts
to Broker
, and the Provider
will read and verify the contracts
from the Broker
. This allows for even more seamless integration test and the Broker
also has UI to view the result
To startup the broker, navigate to root directory and run
docker-compose up -d
Access via http://localhost:9292
- Since
au.com.dius.pact.consumer:junit5:4.3.0
onwards, when running the test, it will throw errorjava.lang.UnsupportedOperationException: Method getSingleProfile does not conform required method signature 'public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)'
- See test-report, most likely related to this issue and this note
- To overcome this, we can change to
PactSpecVersion.V3
like such@PactTestFor(providerName = "ProfileProvider", pactVersion = PactSpecVersion.V3)
- Seem like
PactSpecVersion.V4
is the default, and is incompatible withV3
- When running the test via
VSCode
(manual click),pact
generated contract will be output totarget/pact
even though usinggradle
. However, if running via command./gradlew build
, there won't be such issue - Unable to publish verification result to broker after running
./gradlew pactVerify
command. Have reported the issue.- Managed to get the result published after some help but still facing issue when using with
gradle plugin
- Managed to get the result published after some help but still facing issue when using with
start.spring.io
wrongly generatedcontracts
astask
instead ofextension
forgradle
- Consumer Driven Contract [Pact] vs Provider Driven Contract [SCC]
- Ease of use
- Learning curve / Overhead
- Both libraries don't provide the best out-of-the-box experience to start as the documentation seem to jump all around, and are quite confusing (sometimes)
- So far, I am using
gradle
to test in my demo, and online is lacking on the support forgradle
. Most of the example are written usingmaven
, and my attempt to usegradle
has faced multiple issues.- Especially when an error occurs, it wasn't quite clear of what exactly is happening. I have to enable
--info or --debug
to see what exactly is the issue - One example was when using
SCC
, in my contract, I did not enclose theresponse.body.email
with quotes, but the error was pointing atLine 5
of thegetAllProfiles.groovy
file which was the start of the contract and was able to know when I turn on--debug
mode
- Especially when an error occurs, it wasn't quite clear of what exactly is happening. I have to enable
- To be fair, if I had chose to use
maven
, the experience should have been better
- In
Pact
,consumer
writes what fields are required in thecontract
before submitting, andprovider
run against it - In
SCC
,provider
provides thestub
andconsumer
run against thestub
, then verify if the fields they need are there - In
SCC
, it seem less straightforward to write contract againstDate
Possibly look into using Spring Cloud Contract with pact-broker Look into scc-multiapi-converter
- pact-workshop-Maven-Springboot-JUnit5
- contract-test-spring-cloud-contract-vs-pact
- pact-jvm-example
- consumer-driven-contract-tests-lessons-learned
- okta-spring-cloud-contract
- scc-contract-dsl-http-top-level-elements
- gradle-springboot-mavenpublish-publication-only-contains-dependencies
- continuous-integration-with-jenkins-artifactory-and-spring-cloud-contract
- spring-cloud-contract
- pact-vs-spring-cloud-contract-tests
- introduction-to-consumer-driven-contract-testing
- way-to-microservices-contract-testing-a-spring/pact-implemantation
- consumer-driven-contract-testing
- howto-consumer-driven-contracts-with-spring-cloud-contract
- pact-jvm-demo
- pact examples
- event-driven-architecture-how-to-perform-contract-testing-in-kafka-pubsub
- ContractTestingBoilerplate
- how-to-test-java-microservices-with-pact
- consumer-driven-contract-testing-with-pact