How to test integration layer with microservices in docker
My project is written in Java and works with an elastic search that starts as a separate docker container.
Our current integration/component tests are written in
python, they start our app and elastic search as different docker containers, runs tests, and shuts down both of the containers.
I think it'll be much better to rewrite these tests on
java because it's easy for developers when you have a single language throughout a project + you'll get and IDE support. But in this case, it's not clear how to run a docker container from Java test in order to test against it.
Your problem can be broken down into following steps:
- Setup the environment
- Run integration tests
- Tear down the setup
Your thought process of rewriting tests in java does make sense for step-2.
However for setup and tear down, the logic may or may not be in java (I would prefer not). The reason is that there are various tools available for docker management that would take care of step-1 and step-3 which would be much more powerful than doing this via Java.
Even with a simple docker compose file I can do the following:
- Create container for elastic search
- Create container for app with dependency on elastic search
- Create container for running java tests with dependency on app.
The docker compose can run as part of some script that would tear down the setup after a timeout or just notify timeout to the developer giving him the control to debug and solve the issue/s.
Note: This is high level view without going into the smaller details. Please don't consider this as 100% complete/correct.