简体   繁体   English

Pact - 合同测试 - 根据合同验证消费者和生产者

[英]Pact - contract testing - verify consumer and producer against contract

I have made demo application for Pact-Contract testing.我已经为 Pact-Contract 测试制作了演示应用程序。 Following is the link, I referred.以下是我提到的链接。 I have change few things out of that like patternmatcher and bodytype.我已经改变了一些东西,比如patternmatcher和bodytype。 https://www.javacodegeeks.com/2017/03/consumer-driven-testing-pact-spring-boot.html 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.例如,消费者在 json 之后向提供者发布以创建新用户。

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

But now consumer changes the model classes.但现在消费者更改了 model 类。 (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.以下是将生成的新请求 json。

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

As the request object is changed.随着请求 object 发生变化。 If I verify consumer against pact.如果我根据协议验证消费者。 It should fail.它应该失败。

Problem: When I run mvn:verify from consumer, it is always OK.问题:当我从消费者运行 mvn:verify 时,它总是可以的。 I want it to fail.我希望它失败。

PS Let me know if it is not correct way of doing it. PS让我知道这是否是不正确的做法。

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).它不依赖于之前的 state(例如之前生成的合约)。

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 ).检查重大更改的过程部分是在 CI 中使用我可以部署工具 ( https://docs.pact.io/pact_broker/can_i_deploy )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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