Philipp Krenn @xeraa Real Integrat- ion Tests with

Developer

Tests

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

Ok — we need Interation Tests

Mocks

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

embedded-elasticsearch https://github.com/allegro/embedded-elasticsearch

Demo

Customization & Mappings .withPlugin("analysis-stempel") .withIndex("cars", IndexSettings.builder() .withType("car", getSystemResourceAsStream("car-mapping.json"))

! IDE support, customization, custom lifecycle ! Custom integration

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

Build Tool

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

Build a custom 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/

! Standard or custom Docker image ! One instance for all tests, no IDE support

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-javamodule-elasticsearch https://github.com/dadoonet/testcontainers-java-moduleelasticsearch

Work in Progress https://github.com/testcontainers/testcontainers-java/pull/ 826

Demo

Todo Set (randomized) port

! IDE support, customization, custom lifecycle ! Custom integration

Containerized CI? Sidecar Or embedded approach

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 @xeraa