Philipp Krenn @xeraa Real Integrat- ion Tests with Infrastructure - - PowerPoint PPT Presentation

philipp krenn xeraa real integrat ion tests with
SMART_READER_LITE
LIVE PREVIEW

Philipp Krenn @xeraa Real Integrat- ion Tests with Infrastructure - - PowerPoint PPT Presentation

Philipp Krenn @xeraa Real Integrat- ion Tests with Infrastructure | Developer Integration Tests But the unit tests passed, so... https://twitter.com/Aaronius/status/ 933497253347463168 Mocking Mockito, EasyMock, JMock,... Ich


slide-1
SLIDE 1

Philipp Krenn @xeraa Real Integrat-ion Tests with

slide-2
SLIDE 2

Infrastructure | Developer

slide-3
SLIDE 3

Integration Tests

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

But the unit tests passed, so...

https://twitter.com/Aaronius/status/ 933497253347463168

slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11

Mocking

slide-12
SLIDE 12

Mockito, EasyMock, JMock,...

slide-13
SLIDE 13
slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

In-Memory

slide-17
SLIDE 17

H2, HSQLDB, Apache Derby,...

slide-18
SLIDE 18
slide-19
SLIDE 19

Embedded Elasticsearch unsupported in 5.0+

https://www.elastic.co/blog/elasticsearch-the-server

slide-20
SLIDE 20

! Often good enough ! Test real datastore, supported systems

slide-21
SLIDE 21

Actual Datastore

slide-22
SLIDE 22

Local installation Docker container Cloud

slide-23
SLIDE 23

Demo

slide-24
SLIDE 24

! "Good old approach" ! External dependency, parallelization

slide-25
SLIDE 25

In-Process

slide-26
SLIDE 26

de.flapdoodle. embed.process

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

slide-27
SLIDE 27

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

slide-28
SLIDE 28

→ 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

slide-29
SLIDE 29

Build Tool

slide-30
SLIDE 30

docker-maven-plugin

http://dmp.fabric8.io

slide-31
SLIDE 31

Build image: docker:build Run container:

docker:start & docker:stop

slide-32
SLIDE 32

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>

slide-33
SLIDE 33

Demo

slide-34
SLIDE 34

maven-failsafe-plugin

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

slide-35
SLIDE 35

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

slide-36
SLIDE 36

Testcontainers

slide-37
SLIDE 37

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

slide-38
SLIDE 38

Dependency

@ClassRule public static GenericContainer redis = new GenericContainer("redis:3.0.2") .withExposedPorts(6379);

slide-39
SLIDE 39
slide-40
SLIDE 40

testcontainers-java- module-elasticsearch

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

slide-41
SLIDE 41

Demo

slide-42
SLIDE 42

Todo

Set (randomized) port

slide-43
SLIDE 43

! Container per test

Or reuse in static block

! Custom integration

slide-44
SLIDE 44

Conclusion

slide-45
SLIDE 45

Why Integration Tests

slide-46
SLIDE 46

Why not Mocking In-Memory Actual Datastore

slide-47
SLIDE 47

How In-Process Build Tool Testcontainers

slide-48
SLIDE 48

Code

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

slide-49
SLIDE 49

Questions?

Philipp Krenn@xeraa