Integration Testing in Java
Testing (and Integration Testing) is a wide topic. Here I only give some leads for any person who wants to start with unit/integration tests in a distributed system.
Q: Our project contains some micro services based on Maven and Spring boot integrated through REST calls, RabbitMQ, ZooKeeper, MongoDB and some legacy protocols. Can you advise how we would go about testing them?
If you have time, I highly recommend watching this video course - it explains very well how to do integration testing with Spring (of course there are many other video tutorials about the subject).
If you don’t already have written JUnit tests, You may want to start directly with JUnit 5. It was released this year and is supposed to be more convenient than JUnit 4. Mockito is also a “must have” when using JUnit.
For JUnit asserts (JUnit 4 or JUnit 5, it doesn’t matter), I strongly recommend AssertJ (This is what Spring docs recommend, and it is more convenient that JUnit asserts or Hamcrest assertThat).
Spring has very good support for testing a REST API as a Unit test. See for example:
. For solutions “outside” Spring, see these:
- Test a REST API with rest-assured
- Spring Boot inter-service communication testing with WireMock
- WireMock Tutorial: Configuration
- Writing end to end test for a microservices architecture
- Integration Testing with Spring
- JUnit 5 and Rest Assured using Extension API
. Testing 2 processes that communicate through rabbitMQ is complicated and requires a lot of configuration. I would prefer testing each of them separately - sending a message to one process and testing that it really does what it should. Even this in itself is quite difficult to test, so what I did was to code the message receiver so that it directly calls another method, and also create a REST API (it could be internal if you don’t want to publish a REST API) that calls the same method. Then I can test the REST API instead of through the MQ. Sometimes this technique is not possible, because the code relies on properties of the MQ message (e.g headers).
If you must test 2 (or more) processes together with rabbitMQ, you might try Docker. Run each of the processes in a separate docker, run rabbitMQ on a separate docker (you can also run mongoDB on a separate docker), and link all dockers together. This can be done either through docker commands, or through docker-compose (but it could take several hours to configure correctly, especially if you are not already familiar with docker).
My personal suggestion is not to start with Groovy if you are new to Groovy (It is enough work to tackle the tests issues alone, no need to add learning a new language on top of that).
We will contact you as soon as possible.