Reputation: 759
I'd like to write a end to end test for a pipeline, built with spring boot.
Consider two microservices A, B where B consumes output from A and produces a RESTful API. They are connected using rabbitmq and rely on an external database.
I would like to achieve something like:
Essentially replacing the white parts with mocks and testing the coloured parts.
Does this make sense? Test coverage of A and B is not complete and such a test would guarantee that the contract between A and B holds. Are there better ways?
Upvotes: 3
Views: 11302
Reputation: 703
Another approach is to test each component in isolation and mock the dependent service on the other side of the RabbitMQ server. You can do this using an async API simulation/mocking tool.
For example you can use Traffic Parrot which can be run in a Docker container as part of your CI/CD pipeline.
Here is a video demo of how you can use the tool to send mock response messages to a RabbitMQ queue in an aysnc request/response pattern. There is also a corresponding tutorial available to follow.
Upvotes: 2
Reputation: 3141
My first idea about this topic is that if it is an end-to-end test, then you should forget which framework do you use, because that relates to implementation in this context. So I would create a test project, which is essentially a docker-compose file, and defines 5 containers for
From this perspective you have 2 ways of handling env-specific configuration:
SPRING_PROFILES_ACTIVE
env var in the docker-compose fileThe test runner can be kept simple, I would write a JUnit-based test suite which uses RestAssured, or something similar.
I hope this gives a clue. Of course it is a broad topic so going into every detail doesn't fit into a SO answer.
Upvotes: 3
Reputation: 983
I would recommend you to use Spring-cloud-contract. It helps you in maintaining contract between your microservices(Producer-Consumer Contracts). It's available for both HTTP based and event-based communication.
Upvotes: 2
Reputation: 3805
If you have the time, I suggest you to read this : https://martinfowler.com/articles/microservice-testing/
The purpose of end-to-end testing is not to do 100% of line coverage.
Upvotes: 4