Philipp Krenn @xeraa Real Integrat- 444 ion Tests with

Infrastructure | Developer !

Integration Tests

But the unit tests passed, so... https://twitter.com/Aaronius/status/ 933497253347463168

Mocking

Mockito, EasyMock, JMock,...

Ich mock mir die Welt widdewidde wie sie mir gefällt

! Unit tests, systems not under your control ! Test real datastore

In-Memory

H2, HSQLDB, Apache Derby,...

Embedded Elasticsearch unsupported in 5.0+ https://www.elastic.co/blog/elasticsearch-the-server

! Often good enough ! Test real datastore, supported systems

Actual Datastore

Local installation Docker container Cloud

Demo

! "Good old approach" ! External dependency, parallelization

In-Process

de.flapdoodle. embed.process https://github.com/flapdoodle-oss/ de.flapdoodle.embed.process

...will provide a platform neutral way for running processes in unittests.

→ MongoDB de.flapdoodle.embed.mongo → Redis de.flapdoodle.de.embed.redis → Memcached de.flapdoodle.embed.memcached → PostgreSQL ru.yandex.qatools.embed → MySQL com.wix.mysql → Consul com.github.golovnin.embedded.consul → Vault com.github.golovnin.embedded.vault → InfluxDB io.apisense.embed.influx

Build Tool

docker-maven-plugin http://dmp.fabric8.io

Build image: docker:build Run container: docker:start & docker:stop

Dockerfile or Docker assembly < build

< from

java:8 </ from

< assembly

< descriptor

docker-assembly.xml </ descriptor

</ assembly

< cmd

< shell

java -jar /maven/service.jar </ shell

</ cmd

</ build

Demo

maven-failsafe-plugin https://maven.apache.org/surefire/maven-failsafe-plugin/

! Plain or custom Docker image ! One instance for all tests

Testcontainers

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases [...] that can run in a Docker container.

Dependency @ClassRule public

static GenericContainer redis =

new GenericContainer( "redis:3.0.2" ) .withExposedPorts( 6379 );

testcontainers-java- module-elasticsearch https://github.com/dadoonet/testcontainers-java-module- elasticsearch

Demo

Todo Set (randomized) port

! Container per test Or reuse in static block ! Custom integration

Conclusion

Why Integration Tests

Why not Mocking In-Memory Actual Datastore

How In-Process Build Tool Testcontainers

Code https://github.com/xeraa/integration- test-demo

Questions? Philipp Krenn 4444 @xeraa