“Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests...
Transcript of “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests...
![Page 1: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/1.jpg)
XP Days, 09.11.2018
Testen von und mit Infrastruktur“Integration Testing Done Right“ 😉
Sandra [email protected]
@SandraParsick
![Page 2: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/2.jpg)
Zu meiner Person
● Sandra Parsick
● Freiberuflicher Softwareentwickler und Consultant im Java-Umfeld
● Schwerpunkte:
– Java Enterprise Anwendungen
– Agile Methoden
– Software Craftmanship
– Automatisierung von Entwicklungsprozessen
● Trainings
● Workshops
● Softwerkskammer Ruhrgebiet
● Twitter: @SandraParsick
● Blog: http://blog.sandra-parsick.de
● E-Mail: [email protected]
![Page 3: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/3.jpg)
Motivation
![Page 4: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/4.jpg)
![Page 5: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/5.jpg)
![Page 6: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/6.jpg)
![Page 7: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/7.jpg)
![Page 8: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/8.jpg)
Testen mit Infrastruktur
![Page 9: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/9.jpg)
Status Quo
● Interaktion mit Infrastruktur wird recht spät getestet
– Feedback bei Fehlern recht spät
● Abhängig von einer bestimmten Infrastruktur
– Manchmal auch schon beim Build (Bad smell)
– False negative Fehlerquote recht hoch
– Aufwändiges Setup
– Testausführung langsam
![Page 10: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/10.jpg)
Integration vs Integrated Tests
Integrated TestsA test that will pass or fail based on the correctness of another
system.J.B.Rainsberger
Signs for having Integrated Tests:● We spin up other services in a local testing environment● We test against other services in a shared testing
environment● Changes to your system breaks tests for other systems
from Spotify Blog Post
![Page 11: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/11.jpg)
![Page 12: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/12.jpg)
Anforderungen
● Build muss unabhängig von anderen Systemen sein
– Minimierung der false negative Fehler
– Entkopplung zwischen den Entwicklern
● Feedback bei Fehlern so schnell wie möglich
● Testausführung beschleunigen
![Page 13: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/13.jpg)
HTTP Datenbank
![Page 14: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/14.jpg)
HTTP
![Page 15: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/15.jpg)
Mocking HTTP Calls
● MockServer (http://mock-server.com/ )
● WireMock (http://wiremock.org/ )
Quelle: mock-server.com
![Page 16: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/16.jpg)
MockServer
● Java und JavaScript API
● Java Rule
● Maven Plugin
● Npm Plugin
● Grunt Plugin
● Standalone (CLI)
● Docker Container
![Page 17: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/17.jpg)
MockServer
Quelle: mock-server.com
![Page 18: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/18.jpg)
MockServer
Quelle: mock-server.com
![Page 19: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/19.jpg)
http://swapi.co/api/starships
![Page 20: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/20.jpg)
![Page 21: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/21.jpg)
![Page 22: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/22.jpg)
Don’t mock API you don’t own
![Page 23: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/23.jpg)
Verified FakesTests, die die richtige API aufrufen und verifizieren ob die
Test Doubles richtig sind
![Page 24: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/24.jpg)
Datenbanken
![Page 25: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/25.jpg)
Datenbanken● Embedded Datenbanken
– H2, Derby
– Nicht Produktionsnah
– Nicht alles testbar
● Standalone Datenbanken
– Abhängigkeit zur bestimmten Infrastruktur
● Shared Datenbanken
– Abhängigkeiten zwischen Entwickler
– Hohe false negative Fehlerrate
![Page 26: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/26.jpg)
![Page 27: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/27.jpg)
![Page 28: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/28.jpg)
![Page 29: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/29.jpg)
![Page 30: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/30.jpg)
Testcontainers● Temporary database containers - spezielle MySQL,
PostgreSQL, Oracle XE und Virtuoso container ● Webdriver containers - Dockerized Chrome oder Firefox
browser für Selenium/Webdriver Operationen mit automatischer Videoaufnahme
● Kafka container – Dockerized Kafka (einzelner Knoten)● Generic containers – irgendein Docker Container● Docker compose – Wiederverwendung von Docker Compose
YAML Datei● Dockerfile containers – Container direkt von einem Dockerfile
![Page 31: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/31.jpg)
Docker Maven Plugin (DMP)
● fabric8io/docker-maven-plugin (http://dmp.fabric8.io )
● Kann Docker Image bauen
● Aber auch Container starten und stoppen
![Page 32: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/32.jpg)
Maven Phase: Integration-Test● Ausgangspunkt:
– Es gibt Integrationstests gegen embedded oder standalone Datenbank
● Improvement:
– DMP startet Container vor den Tests (pre-integration-test)
– DMP stoppt Contianer nach den Tests (post-integration-test)
![Page 33: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/33.jpg)
Testen von Infrastruktur
![Page 34: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/34.jpg)
![Page 35: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/35.jpg)
Infrastructure as Code
● Shell Skripte
– Bash, ksh, etc
● Provisionierungswerkzeuge
– Puppet, Chef, Salt und Ansible
● Container
– Dockerfile
![Page 36: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/36.jpg)
Provisionierungswerkzeuge(Beispiel Ansible)
● Codequalität
– ansible-lint (https://github.com/willthames/ansible-lint)
● Funktionale Qualtität
– Serverspec (Tool unabh.)(https://serverspec.org/ )
– Testinfra (Tool unabh.)(https://testinfra.readthedocs.io/en/latest/ )
![Page 37: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/37.jpg)
![Page 38: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/38.jpg)
Ansible-Lint
![Page 39: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/39.jpg)
testinfra
![Page 40: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/40.jpg)
testinfra
![Page 41: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/41.jpg)
Jenkins Pipeline
![Page 42: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/42.jpg)
Container (Beispiel Docker)● Codequalität
– Dockerlint (https://github.com/RedCoolBeans/dockerlint )
– Haskell Dockerfile Linter – hadolint (https://github.com/hadolint/hadolint)
● Funktionale Qualität
– Testinfra
– Serverspec
– Container Structure Tests https://github.com/GoogleContainerTools/container-structure-test
![Page 43: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/43.jpg)
![Page 44: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/44.jpg)
Hadolint
![Page 45: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/45.jpg)
Container Structure Tests
![Page 46: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/46.jpg)
Container Structure Tests
Vorher: docker build -t sparsick/tomcat9 -f tomcat.df .
![Page 47: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/47.jpg)
Fazit
![Page 49: “Integration Testing Done Right“ - XP Days · Integration vs Integrated Tests Integrated Tests A test that will pass or fail based on the correctness of another system. J.B.Rainsberger](https://reader036.fdocuments.us/reader036/viewer/2022071011/5fc9ff4680caf516dd691808/html5/thumbnails/49.jpg)
Literatur
● http://coding-is-like-cooking.info/2018/04/pre-tested-integration-back-to-the-basis-of-ci/
● http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam
● http://blog.thecodewhisperer.com/permalink/clearing-up-the-integrated-tests-scam
● https://bee42.com/de/blog/The_dark_age_of_container_testing/
● https://labs.spotify.com/2018/01/11/testing-of-microservices/
● https://martinfowler.com/bliki/IntegrationTest.html?utm_content=buffer2b62b&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer
● https://codewithoutrules.com/2016/07/31/verified-fakes/
●