Ask a Question

How to validate requests sent to a mock server against a contract

scott_myob
Frequent Visitor

How to validate requests sent to a mock server against a contract

When I test a service, I often mock interactions with other services so that I am only testing the code that I care about. If the interaction I am mocking has an OpenAPI contract, I want to be able to validate that the request and response being mocked both comply with the contract.

 

This seems like it should be a very common use of Swagger / OpenAPI contracts, but the only tool I can find that does this is this one written by Atlassian in Java https://bitbucket.org/atlassian/swagger-request-validator. I don't want to use Java, and if there is a lack of tools in this area that indicates that what I am trying to do is wrong for some reason.

 

Are there any other tools that do this? I have looked everywhere and haven't found any. Or does everyone who wants to do "contract testing" instead use PACT? Or am I just crazy for trying to use this approach?

 

 

Example:

  • Let's pretend that I have a system that sends emails to a database of users
  • The system is comprised of two microservices, Notifications and Users
  • Notifications consumes Users
  • I have an OpenAPI contract for Users
  • When I test Notifications, I would mock the interation with Users.
  • To ensure the integration is correct, I want to be able to validate that the request I am sending to Users and the fake response I am mocking, actually matches the Users contract.
  • The only options I can find to do this currently is PACT, or use the Java swagger-request-validator
cancel
Showing results for 
Search instead for 
Did you mean: