Java 8+
On Windows use gradlew.bat
instead of ./gradlew
There are too projects: provider and consumer, each in it separate directory. Start gradlew commands from inside the appropriate project.
- Start provider with
./gradlew bootRun
- Check that provider is running, with Postman/curl or any other API tool. Request http://localhost:8888/weather/now?city=Berlin and observe the JSON response.
- Stop the provider (Ctrl+C)
- Inspect Consumer method which call the provider:
Controller.weatherNow(...)
- Inspect
PactWeatherTest
class, especiallycreatePact()
andunitTestCustomerMethod()
- Create Pact and test customer with:
./gradlew test
- Inspect created Pact JSON in target/pacts directory
- Make some changes in
createPact()
, run./gradlew test
, inspect how pact file changes - Make some changes to
unitTestCustomerMethod()
and/orController.weatherNow()
to get the test failed/passed back. - Add a test method (similar to
unitTestCustomerMethod
, but calling another URL) - observe the pact test failed with explanation (Pact must describe all interactions from test) - Leave a single test method with empty content - observed that the test fails (Pact interaction is described, but not called/tested)
- Make Pact test pass again
- Uncomment code in
build.gradle
(inspect it) - Run
./gradlew verifyPact
- it should fail (provider is not started) - Start the provider in separated session (
./gradlew bootRun
) - Run
./gradlew verifyPact
again - it should pass - Stop the provider
- Inspect code of
PactTest
class, pay attention of configuration annotations - Run
./gradlew test
- it should pass (starting the provider before the test) - Change configuration annotations values (folder, provider name) to fail the test, observe the error messages.
- Return everything back to passing test
Note: You can verify with either ./gradlew clean verifyPact
or with ./gradlew clean test
. When test fails, look for explaining messages in gradle HTML reports.
- Change format of Provider response - in class
Weather
renamezipCode
property/methods - Verify pact - it must be passing (change doesn't make pact invalid)
- Change format of Provider response - in class
Weather
renamecity
property/methods - Verify pact - it must be failing (change made pact invalid)
- Consumer: make changes to pact, rerunning the test (to generate new pact json)
- Inspect which effect does it have to pact verification by provider
Feel free to change code on both side, observing the effects.