Search code examples
testingfrontendfunctional-testing

Functional testing: How to keep a backend mock up to date


For running functional tests against a front-end, we are considering mocking our backend. Our backend iterates quite fast and changes a lot, though. So mocking it would mean we'd always need to be aware of all changes and update our mocks accordingly.

I was wondering if it is possible to automate this process.


Solution

  • What you're going to do is something related to Consumer Driven Contracts

    Some time ago we had a similar need, and we've developed java based tool, which now exists under Spring Cloud Contract. If you're using a non-java backend you can try Pact which supports Java as well as other languages, but is harder to incorporate in JVM world. Spring Cloud Contract also supports messaging support (JMS, RabbitMQ, etc).

    The main idea is that you're writing the contract of your backend service, and this contract is used to generate two artifacts:

    1. mocks for the client side (in your case frontend)
    2. tests for the service side (in your case backend)

    Then you can incorporate service tests in your delivery pipeline and be sure that your backend is consistent with the mock, which you used to test the frontend application.