简体   繁体   中英

Pact - contract testing - verify consumer and producer against contract

I have made demo application for Pact-Contract testing. Following is the link, I referred. I have change few things out of that like patternmatcher and bodytype. https://www.javacodegeeks.com/2017/03/consumer-driven-testing-pact-spring-boot.html

I am able to publish pact from consumer and verify it from provider side.

I have been asked to verify pact from consumer end as well. Eg consumer posts following json to provider for creating new user.

  {
  "address": {
    "city": "string",
    "houseNumber": 0,
    "postalCode": "string",
    "street": "string"
  },
  "name": "string",
  "registrationId": 0,
  "surname": "string"
}

But now consumer changes the model classes. (as it is also provider for some other service. it might be possible to get request to change change contract). Following is the new request json that will be generated.

{
  "address": {
    "city": "string",
    "houseNumber": 0,
    "postalCode": "string",
    "street": "string"
  },
  "firstname": "string",
  "registrationId": 0,
  "surname": "string"
}

As the request object is changed. If I verify consumer against pact. It should fail.

Problem: When I run mvn:verify from consumer, it is always OK. I want it to fail.

PS Let me know if it is not correct way of doing it.

The consumer test is analogous to a unit test. It will always pass if your code does what you expect it to in the test. It isn't dependent on prior state (such as a previous generated contract).

The part of the process where you would check for a breaking change is in CI with the can I deploy tool ( https://docs.pact.io/pact_broker/can_i_deploy ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM