hardik.rajani
hardik.rajani

Reputation: 31

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. E.g. 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.

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

Upvotes: 0

Views: 538

Answers (1)

Matthew Fellows
Matthew Fellows

Reputation: 4065

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).

Upvotes: 0

Related Questions