SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Consumer-Driven Contract
Testing - ein Überblick_
Tobias Flohre
10.05.2017
Agenda_
Testing
Consumer-Driven Contract Testing - das Prinzip
PACT
Spring Cloud Contract
Gegenüberstellung / Fazit
2
Testpyramide_
Martin Fowler / Mike Cohn - Succeeding with Agile
3
Testpyramide_
4
Unit-Tests
Integration-Tests
End2End
Tests
JUnit
Mockito
JUnit
Spring TestContext
Arquillian
Selenium
Docker
Robot
Build-Job
Maven
Jenkins
Build-Job
Maven
Jenkins
Testumgebung
Maven
Jenkins
Testpyramide_
5
Unit-Tests
Integration-Tests
End2End
Tests
Testpyramide_
6
Unit-Tests
Integration-Tests
Verteilte Systeme und Testing_
7
Unit
Integration
Unit
Integration
Unit
Integration
Unit
Integration
Unit
Integration
End2End
8
End2End
Verteilte Systeme und Testing_
9
End2End
Verteilte Systeme und Testing_
10
Consumer Driven Contracts - Das Prinzip_
Consumer Driven Contracts - Das Prinzip_
11
Consumer Driven Contracts - Das Prinzip_
12
Consumer
Provider
Consumer Driven Contracts - Das Prinzip_
13
Consumer
Provider
•Consumer erstellt Contract
• abgestimmte Syntax
•Provider implementiert Contract
•Contracts werden bei jedem Build geprüft
•Kommunikation!
14
Consumer Driven Contracts - Das Prinzip_
•Fragen
• Wo werden die Contracts gespeichert?
• In welcher Form werden die Contracts gehalten?
• Wie werden die Contracts ausführbar gemacht?
• Was wird an Infrastruktur benötigt?
• Wie betten sich die Tests in die CI-/CD-Pipeline ein?
• Welche Art der Kommunikation kann ich so testen?
PACT_
15
Copyright © DiUS 2017
PACT_
16
Copyright © DiUS 2017
PACT_
17
•Zentrales Element: pact file
• beschreibt den Contract
• technologieunabhängig
{
"provider": {
"name": "MitarbeiterProvider"
},
"consumer": {
"name": "MitarbeiterConsumer"
},
"interactions": [{
"providerState": "mitarbeiter_geladen",
"description": "Ermittlung Mitarbeiter",
"request": {
"method": "GET",
"path": "/mitarbeiter"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json;charset=UTF-8"
},
"body": [{
"name": "Tobias"
}, {
"name": "Marcel"
}]
}
}],
"metadata": {
"pact-specification": {
"version": "2.0.0"
},
"pact-jvm": {
"version": "2.1.13"
}
}
}
PACT_
18
•Consumer generiert pact file
•Abhängig von der Sprache / Bibliothek
• sehr viele Implementierungen
•JVM: JUnit
PACT_
19
20
•Consumer testet pact selbst
PACT_
21
•Provider prüft den Contract anhand pact file
• sehr viele Implementierungen
•JVM
• Maven- / Gradle-Plugin
• JUnit
• Spring MVC
PACT_
22
•Beispiel: Maven-Plugin - Konfiguration
• Referenz auf pact files
• Provider muss laufen
• mvn pact:verify
PACT_
23
•Beispiel: Maven-Plugin - Konfiguration
• State Change URL
PACT_
24
•Wie starten wir die Anwendung?
•Wie halten wir die pact files?
PACT_
25
•Wie starten wir die Anwendung?
• Abhängigkeiten
• Testdaten / stateChangedUrl
• Job 1 baut
• Job 2 deployed in
Testumgebung
• Job 3 startet mvn pact:verify
• Job 1 baut
• Job 2 startet Anwendung lokal
(bspw. Spring Boot Maven Plugin)
• Job 2 führt das verify aus
• Job 2 stoppt Anwendung
PACT_
26
•Wie halten wir die pact files?
• Pact Broker
• Dokumentation / Netzwerkdiagramme
• Tags (prod/dev)
• Webhooks
PACT_
PACT_
27
ProviderConsumer
2. build
PACT Broker
1. add contract
•Workflow Entwicklung Consumer
3. publish pact DEV
4. trigger provider verify DEV
PACT_
28
Provider
Consumer
2. build
PACT Broker
1. trigger release
•Workflow Release Consumer
3. publish pact PROD
4. trigger provider verify PROD
5. deploy if (4) successful
PACT_
29
Provider
2. build
PACT Broker
1. implement
•Workflow Entwicklung / Release Provider
3. verify pacts DEV
4. verify pacts PROD
5. deploy if (4) successful
Spring Cloud Contract_
30
•Basisfakten
• beschränkt auf JVM
• in erster Linie Spring
• kann auch Messaging
• klarer Workflow
Spring Cloud Contract_
31
lokal
Provider
Consumer
1. fork
Provider-Fork
2. add contract
•Workflow
Spring Cloud Contract - Groovy DSL_
32
package contracts
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'PUT'
url '/fraudcheck'
body([
"client.id": $(regex('[0-9]{10}')),
loanAmount: 99999
])
headers {
contentType('application/json')
}
}
response {
status 200
body([
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"
])
headers {
contentType('application/json')
}
}
}
Spring Cloud Contract_
33
lokal
Provider
Consumer
1. fork
Provider-Fork
2. add contract
3. publish stubs
locally
4. write tests
using stubs
•Workflow
34
•Maven-Plugin generiert Stubs
• Wiremock-Stubs
• Stubs werden mit classifier -stubs in Maven Repo geladen
•Tests starten und verwenden Stubs
Spring Cloud Contract_
Spring Cloud Contract_
35
lokal
Provider
Consumer
1. fork
Provider-Fork
2. add contract
3. publish stubs
locally
4. write tests
using stubs
5. submit PR
6. write implementation
7. write test base class
8. build and publish stubs
•Workflow
36
•Provider: Maven-Plugin generiert
Stubs und Tests
• Modi für Testgenerierung:
MockMvc, Explicit
• Tests erben von einer Basis-Klasse,
die selbst implementiert werden
muss -> Hier wird Infrastruktur
initialisiert
•Provider muss nicht laufen bei Ausführung der Tests!
Spring Cloud Contract_
Spring Cloud Contract_
37
lokal
Provider
Consumer
1. fork
Provider-Fork
2. add contract
3. publish stubs
locally
4. write tests
using stubs
5. submit PR
6. write implementation
7. write test base class
8. build and publish stubs
9. use stubs
•Workflow
38
stubrunner:
repositoryRoot: https://nexus/demo/libs-release
•application yaml
•workOffline deaktivieren
Spring Cloud Contract_
Spring Cloud Contract_
39
lokal
Provider
Consumer
1. fork
Provider-Fork
2. add contract
3. publish stubs
locally
4. write tests
using stubs
5. submit PR
6. write implementation
7. write test base class
8. build and publish stubs
9. use stubs
•Workflow
40
•Spring RestDocs zum Generieren der Contracts / Stubs
• Provider-driven
•pact files als Contract
Spring Cloud Contract_
Fazit_
41
•Einbindung in CI/CD ist elementar
• Continuous Deployment passt am besten
• Stark branch-basiertes Arbeiten hinderlich
•Spring Cloud Contract bietet etwas mehr im Messaging-
Bereich
•Pact ist technologie-unabhängig
•Pact: DSL wird im Consumer-Projekt verwendet
• Keine global verwendbaren Stubs
•SCC: DSL wird per Fork ins Provider-Projekt eingebracht
• Generierte Stubs mit Provider versioniert
• global verwendbar
01
Fragen?
Tobias Flohre
codecentric AG
Hochstraße 11
42697 Solingen, Deutschland
www.codecentric.de
blog.codecentric.de
@tobiasflohre

Más contenido relacionado

Similar a Consumer- Driven Contract Testing - ein Überblick

Serverprovisioning in einer dynamischen Infrastruktur
Serverprovisioning in einer dynamischen InfrastrukturServerprovisioning in einer dynamischen Infrastruktur
Serverprovisioning in einer dynamischen Infrastruktur
inovex GmbH
 
Grundlagen puppet
Grundlagen puppetGrundlagen puppet
Grundlagen puppet
inovex GmbH
 
Creasoft Akademie - Deep Dive into ASP.NET MVC
Creasoft Akademie - Deep Dive into ASP.NET MVCCreasoft Akademie - Deep Dive into ASP.NET MVC
Creasoft Akademie - Deep Dive into ASP.NET MVC
Creasoft AG
 
Creasoft Akademie - Deep dive into ASP.NET MVC
Creasoft Akademie - Deep dive into ASP.NET MVCCreasoft Akademie - Deep dive into ASP.NET MVC
Creasoft Akademie - Deep dive into ASP.NET MVC
Creasoft AG
 

Similar a Consumer- Driven Contract Testing - ein Überblick (20)

Composer und TYPO3
Composer und TYPO3Composer und TYPO3
Composer und TYPO3
 
Ant Maven
Ant MavenAnt Maven
Ant Maven
 
Unit Testing einer Zend-Framework 2 Anwendung
Unit Testing einer Zend-Framework 2 AnwendungUnit Testing einer Zend-Framework 2 Anwendung
Unit Testing einer Zend-Framework 2 Anwendung
 
CDI
CDICDI
CDI
 
TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)TYPO3 Performance (TYPO3camp München)
TYPO3 Performance (TYPO3camp München)
 
MVVM mit WPF
MVVM mit WPFMVVM mit WPF
MVVM mit WPF
 
The Best Things in Life Are Free – Wie Sie Ihre IBM ConnecEons Umgebung koste...
The Best Things in Life Are Free – Wie Sie Ihre IBM ConnecEons Umgebung koste...The Best Things in Life Are Free – Wie Sie Ihre IBM ConnecEons Umgebung koste...
The Best Things in Life Are Free – Wie Sie Ihre IBM ConnecEons Umgebung koste...
 
Serverprovisioning in einer dynamischen Infrastruktur
Serverprovisioning in einer dynamischen InfrastrukturServerprovisioning in einer dynamischen Infrastruktur
Serverprovisioning in einer dynamischen Infrastruktur
 
Continous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickelnContinous Deployment - Schneller entwickeln
Continous Deployment - Schneller entwickeln
 
AdminCamp 14 - IBM Connections Deep Dive
AdminCamp 14 - IBM Connections Deep DiveAdminCamp 14 - IBM Connections Deep Dive
AdminCamp 14 - IBM Connections Deep Dive
 
Plsql drum test automatisiere, wer sich sich ewig bindet! - DOAG 2017
Plsql drum test automatisiere, wer sich sich ewig bindet! - DOAG 2017Plsql drum test automatisiere, wer sich sich ewig bindet! - DOAG 2017
Plsql drum test automatisiere, wer sich sich ewig bindet! - DOAG 2017
 
Grundlagen puppet
Grundlagen puppetGrundlagen puppet
Grundlagen puppet
 
Vortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development EnvironmentsVortragsreihe Dortmund: Unified Development Environments
Vortragsreihe Dortmund: Unified Development Environments
 
Ionic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenIonic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf Steroiden
 
WPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF RundumschlagWPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF Rundumschlag
 
Vagrant
VagrantVagrant
Vagrant
 
Creasoft Akademie - Deep Dive into ASP.NET MVC
Creasoft Akademie - Deep Dive into ASP.NET MVCCreasoft Akademie - Deep Dive into ASP.NET MVC
Creasoft Akademie - Deep Dive into ASP.NET MVC
 
Creasoft Akademie - Deep dive into ASP.NET MVC
Creasoft Akademie - Deep dive into ASP.NET MVCCreasoft Akademie - Deep dive into ASP.NET MVC
Creasoft Akademie - Deep dive into ASP.NET MVC
 
Fehleranalyse in SCCM
Fehleranalyse in SCCMFehleranalyse in SCCM
Fehleranalyse in SCCM
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in php
 

Consumer- Driven Contract Testing - ein Überblick