Integration testing with RabbitMQ and Postgres in Spring Boot when using CI (and not only)

The application to test uses Postgres and RabbitMQ. It also uses “spring-boot-starter-amqp” and its “RabbitTemplate”. The app runs migrations with Flyway and uses Postgres syntax. Because of inconvenience and since there is CI (Continuous Integration) in a remote server, running RabbitMQ and Postgres instances can’t be provided. How can we set up our test environment to provide those RabbitMQ and Postgres DB instances, so it is clean on each test suite run?

Comments

Very good advice - Docker is everywhere but sometimes one forgets how helpful it can be during testing. I didn't know of Testcontainers yet but this may solve some test automation problems one has when trying to integrate containers in the testing step. In my case it may help myself to move away from H2 as test database to a solution using the same flyway scripts on the same database I use in production.
Artur Marcin Sz... - Mon, 12/10/2018 - 06:59 :::
1 answer

This one is the BEST answer!

For local development it is usually a practise to spawn test containers on a local machine and run them all the time during development.
Also embedded broker/server is also an option, but RabbitMQ and Postgres don’t offer embedded solutions out of the box and setting a custom one would take too much time.
So what you can easily do is spawn local short lived docker containers with these technologies. 
A good and tested solution to this problem is using the Testcontainers test dependency. Test containers
So, with provided RabbitMQ and Postgres images, you just launch containers on Test Suite start and they get automatically destroyed on shutdown.