philipp krenn xeraa real integrat ion tests with
play

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


  1. Philipp Krenn @xeraa Real Integrat- ��� ion Tests with

  2. Infrastructure | Developer

  3. Integration Tests

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

  5. Mocking

  6. Mockito, EasyMock, JMock,...

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

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

  9. In-Memory

  10. H2, HSQLDB, Apache Derby,...

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

  12. ! Often good enough ! Test real datastore, supported systems

  13. Actual Datastore

  14. Local installation Docker container Cloud

  15. Demo

  16. ! "Good old approach" ! External dependency, parallelization

  17. In-Process

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

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

  20. → 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

  21. Build Tool

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

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

  24. 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>

  25. Demo

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

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

  28. Testcontainers

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

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

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

  32. Demo

  33. Todo Set (randomized) port

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

  35. Conclusion

  36. Why Integration Tests

  37. Why not Mocking In-Memory Actual Datastore

  38. How In-Process Build Tool Testcontainers

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

  40. Questions? Philipp Krenn ���� @xeraa

Recommend


More recommend