Introduction

Just to make long story short - Accurest is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped with Contract Definition Language (DSL). Contract definitions are used by Accurest to produce following resources:

  • JSON stub definitions to be used by Wiremock when doing integration testing on the client code (client tests). Test code must still be written by hand, test data is produced by Accurest.

  • Messaging routes if you’re using one. We’re integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to

  • Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (server tests). Full test is generated by Accurest.

Accurest moves TDD to the level of software architecture.

Why?

Let us assume that we have a system comprising of multiple microservices:

Microservices Architecture

Testing issues

If we wanted to test the application in top left corner if it can communicate with other services then we could do one of two things:

  • deploy all microservices and perform end to end tests

  • mock other microservices in unit / integration tests

Both have their advantages but also a lot of disadvantages. Let’s focus on the latter.

Deploy all microservices and perform end to end tests

Advantages:

  • simulates production

  • tests real communication between services

Disadvantages:

  • to test one microservice we would have to deploy 6 microservices, a couple of databases etc.

  • the environment where the tests would be conducted would be locked for a single suite of tests (i.e. nobody else would be able to run the tests in the meantime).

  • long to run

  • very late feedback

  • extremely hard to debug

Mock other microservices in unit / integration tests

Advantages:

  • very fast feedback

  • no infrastructure requirements

Disadvantages:

  • the implementor of the service creates stubs thus they might have nothing to do with the reality

  • you can go to production with passing tests and failing production

To solve the aforementioned issues Accurest with Stub Runner were created. Their main idea is to give you very fast feedback, without the need to set up the whole world of microservices.

Stubbed Services

If you work on stubs then the only applications you need are those that your application is using directly.

Stubbed Services

Accurest gives you the certainty that the stubs that you’re using were created by the service that you’re calling. Also if you can use them it means that they were tested against the producer’s side. In other words - you can trust those stubs.

Purposes

The main purposes of Accurest with Stub Runner are:

  • to ensure that WireMock / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will do,

  • to promote ATDD method and Microservices architectural style,

  • to provide a way to publish changes in contracts that are immediately visible on both sides,

  • to generate boilerplate test code used on the server side.

Client Side

During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y. You would like to feed that instance with a proper stub definition. That stub definition would need to be valid and should also be reusable on the server side.

Summing it up: On this side, in the stub definition, you can use patterns for request stubbing and you need exact values for responses.

Server Side

Being a service Y since you are developing your stub, you need to be sure that it’s actually resembling your concrete implementation. You can’t have a situation where your stub acts in one way and your application on production behaves in a different way.

That’s why from the provided stub acceptance tests will be generated that will ensure that your application behaves in the same way as you define in your stub.

Summing it up: On this side, in the stub definition, you need exact values as request and can use patterns/methods for response verification.

Dependencies

Accurest and Stub Runner are using the following libraries

Below you can find some resources related to Accurest and Stub Runner. Note that some can be outdated since the Accurest project is under constant development.

Videos

Olga Maciaszek-Sharma talking about Accurest

Marcin Grzejszczak and Jakub KubryƄski talking about Accurest

Samples

Here you can find some working samples. Check the readme of each project for more information.