Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Real Integration Tests with TestContainers

Real Integration Tests with TestContainers

How are you doing integration tests with your datastore?

* Mocking is not an option since you want to test the actual system.
* There are some in-memory implementations, like H2 or HSQLDB for relational databases, but there are still subtle differences to your production system and not all datastores have in-memory cousins.
* Using the actual datastore in your tests is possible, but managing it, running tests in parallel,... is far from ideal.

So what is the solution? There is a very neat solution based on containers: TestContainers. From your tests you can start a lightweight, throwaway instance of your datastore and this talk will walk you through on how to do that as well as alternatives with docker-maven-plugin.

Philipp Krenn

January 29, 2019
Tweet

More Decks by Philipp Krenn

Other Decks in Programming

Transcript

  1. Docker Compose integration @ClassRule public static DockerComposeContainer environment = new

    DockerComposeContainer(new File("src/test/resources/compose.yml")) .withExposedService("elasticsearch_1", ELASTICSEARCH_PORT, Wait.forHttp("/").forStatusCode(200));
  2. [Ryuk] drops a Death Note, a notebook that allows the

    user to kill anyone simply by knowing their name and face https://en.wikipedia.org/wiki/Ryuk_(Death_Note)
  3. $ docker run -it --rm -v $PWD:$PWD -w $PWD -v

    /var/run/docker.sock:/var/run/docker.sock maven:3 mvn --projects parent,4_testcontainers-custom test $ docker ps -a