Arpit
Arpit

Reputation: 310

Consumer driven contracts

Is there a way to check consumer contracts in unit tests for micro services? I know we can use Pact library in java while doing integration testing via JUnit. But i wonder if there is a way to do the same with unit tests?

Upvotes: 1

Views: 598

Answers (1)

Ali Sağlam
Ali Sağlam

Reputation: 1520

Spring Cloud Contract is another handy tool that i can suggest. It is well documented and the creators of the api answer your question fast in different environments(e.g. Gitter, Github). The framework works on both producer and consumer side. It ensures the api is compatible with the contracts defined by the consumer on the producer side. On producer side tests are generated automatically. The contracts are also shared with the consumer in a tricky way. They are pushed to your local artifact repository (e.g. Nexus, Artifactory) and consumer can access the contracts over the repo. After that, consumer can also check whether it works with the api written on producer or not. It can be used in also publish-subscribe mechanism. Great tool, use it.

By the way; You can mock your beans and test contracts compatibility in a way that you it looks like unit test, but i dont understand why you insist on testing with unit test.

Regards...

Upvotes: 2

Related Questions