Slide 1

Slide 1 text

Consumer-driven Contract Testing Stephan Stapel, Hermes Germany Bochum, March 13, 2019

Slide 2

Slide 2 text

Stephan Stapel • 43 years old • Head of Development (Customer Solutions) • Areas of interest: Agility, applying Lean principles in IT (DevOps, Continuous Delivery)

Slide 3

Slide 3 text

Agenda 01 The case for Consumer-based Contract Testing (CDCT) 02 Using CDCT 03 Summary

Slide 4

Slide 4 text

01 The case for CDCT

Slide 5

Slide 5 text

Hermes Germany is the second largest parcel delivery company in Germany. • Hermes Germany is Hamburg-based • Part of the Otto group • We deliver about 400 million parcels per year. • There are 4 competing parcel delivery companies in Germany. • IT is the key differentiator for Hermes.

Slide 6

Slide 6 text

Almost no standard software is available for our business. • Focus on inhouse development • Numerous medium-sized applications • Microservices to-the-rescue • Lots of concurrent development activity

Slide 7

Slide 7 text

Highly integrated application landscape • Numerous applications to be integrated • Verticalization (Microservices) • Horizontalization (SOA components providing base functionality for the entire application landscape)

Slide 8

Slide 8 text

Continuous Delivery helps us to shorten development cycles. Develop Test Deploy Build Develop Modern frameworks generate most boilerplate parts automatically. Build Jenkins makes it effortless to build, run and automatize our pipelines. Deploy Jenkins and K8s – both make deployment processes and infrastructure management easier. Test Unit tests and BDD can easily be automated.

Slide 9

Slide 9 text

Automatization reaches its limits when it comes to crossing team boundaries. 9 Consumer Provider Team 1 Team 2

Slide 10

Slide 10 text

With a close-to-perfect development process in place, collaboration between teams becomes the next bottleneck. Agreeing on the interface Implementing functionality Implementing functionality Implementing interface call Integration tests and End2End tests Team 1 Deployment Deployment Team 2 Synchronization of teams Synchronization of teams t t Synchronization leads to wait times.

Slide 11

Slide 11 text

When it comes to real-world scenarios, End2End Tests are often too complex and expensive. 11 Team 1 Team 2 Team 3 Team n … End2End Test Implementation Test Implementation Test Implementation Test Implementation Test

Slide 12

Slide 12 text

Skipping End2End Tests in favor of comprehensive Integration Tests reduces effort, assuring landscape quality remains complex and expensive. 12 Team 1 Team 2 Integration Test Team 3 Team n … Integration Test Integration Test … Implementation Test Implementation Test Implementation Test Implementation Test

Slide 13

Slide 13 text

Bottleneck: All teams need to finish their work before Integration Tests and End2End Tests can be kicked off today‘s focus E2E Tests Integration Tests Function Tests/ Module Tests

Slide 14

Slide 14 text

Comprehensive Trustworthy Fast Early Cheap Integration Tests are…

Slide 15

Slide 15 text

Agenda 15 How to solve?

Slide 16

Slide 16 text

Planning Architecture Development & Test We address dependencies on all levels. 16 Value stream roadmap Dependencies are identified early in the process, activities of teams can be aligned. myhermes Microservice Microservice Microservice Microservice CCM Microservice Microservice Microservice Microservice Architecture Mantra: As vertical as possible Effect: clear boundaries facilitate isolation of changes, allow more frequent deployments. Technology Consumer-driven Contract Tests support team interaction and interface negotiations. Consumer Provider

Slide 17

Slide 17 text

Development & Test Planning Architecture We address dependencies on all levels. 17 Value stream roadmap Dependencies are identified early in the process, activities of teams can be aligned. myhermes Microservice Microservice Microservice Microservice CCM Microservice Microservice Microservice Microservice Architecture Mantra: As vertical as possible Effect: clear boundaries facilitate isolation of changes, allow more frequent deployments. Technology Consumer-driven Contract Tests support team interaction and interface negotiations. Consumer Provider

Slide 18

Slide 18 text

Contracts describe customer‘s expectations from the provider. This structured approach speeds up interactions between teams. 18 Consumer Provider 1 Tests Tests Mock Provider 2 Mock Consumer 2 Contract

Slide 19

Slide 19 text

Consumer-driven Provider-driven Why consumer-driven instead of provider-driven? 19 • Fit for purpose • Detect unused functionality • Does not work with unknown consumers (public API) • Well-known concept (APIs) • Broad definition (schema, interface, policy, …) • Authoritative

Slide 20

Slide 20 text

Agenda 20 But: Contracts do not fix broken communication between teams.

Slide 21

Slide 21 text

Decoupling Integration Tests. Consumer Driven Contract Tests allow us to isolate Integration Tests. • Integration Tests locally within the teams • Each focusing on particular services • Stubbing and mocking of the partnering services E2E Tests Integration Tests Function Tests/ Module Tests

Slide 22

Slide 22 text

Provider-centric tests Consumer-centric tests Decoupling Integration Tests. Consumer Driven Contract Tests allow us to isolate Integration Tests. 22 Provider 3 Isolation against third-party services. Provider 2 Isolation against third-party services. Provider Consumer

Slide 23

Slide 23 text

With CDCT in place, wait times are minimized. Synchronization of teams Synchronization of teams Agreeing on the interface and contract design Implementing functionality and Integration Tests Implementing functionality and Integration Tests Team 1 Deployment Deployment Team 2 t t End2End Tests

Slide 24

Slide 24 text

With CDCT in place, wait times are minimized. Team 1 Team 2 t t Contract gets updated Interface is modified Test fails, deployment gets blocked. Deployment Deployment Synchronization of teams Synchronization of teams End2End-Tests Adoption

Slide 25

Slide 25 text

Comprehensive Indicate the overall quality Early Cheap Plus: allow late changes in interface design Consumer-driven Contract Tests are…

Slide 26

Slide 26 text

With a growing number of applications, interactions grow exponentially. Number of applications Interfaces • With a fast growing number of interfaces, Integration Testing becomes more important • Potential killer for lead times Traditional landscape

Slide 27

Slide 27 text

With a growing number of applications, interactions grow exponentially. Number of applications Interfaces • With a fast growing number of interfaces, Integration Testing becomes more important • Potential killer for lead times • Shrinking deployment units and increasing their amount (Microservice architecture), interactions grow even faster Microservice landscape Traditional landscape

Slide 28

Slide 28 text

Reshaping the test pyramid. Function Tests/ Module Tests Integrations Tests E2E Tests • CDCT makes Integration Testing cheaper • This allows more comprehensive test setups • Reduce End2End Tests in favor of automated CDCT Tests • Make sure that business logic tests are implemented as Function Tests (Unit Tests)! No holy grail • All Integration Testing is complex • This is also true CDCT  Don‘t let that stop you!

Slide 29

Slide 29 text

02 Using CDCT

Slide 30

Slide 30 text

Two major frameworks for CDCT Both frameworks provide thorough support for CDCT. You can even use them together. PACT Spring Cloud Contract • Community based • PACT broker as the central component for managing contract lifecycle • Supports REST and AMQP • Polyglot • Spring (Pivotal) backing • Workflow more complicated • Focus on Java

Slide 31

Slide 31 text

Terms used with PACT 31 A pact between consumer and provider describes the consumer’s usage patterns of the interface. It consists of one or more provider states. A provider state can be understood as a fixture that the provider generates for a certain request.

Slide 32

Slide 32 text

Example 1 The contract can be modelled in either DSL or Java

Slide 33

Slide 33 text

Example 1 Using the mock provider to run tests on consumer side 33

Slide 34

Slide 34 text

Running the tests on provider side. Test cases are generated automatically based on the contract. 36

Slide 35

Slide 35 text

Test results on provider side: 37

Slide 36

Slide 36 text

Employing the PACT broker for centrally managing your contracts 39 Consumer .json file Option 1 PACT broker Contract Option 2 Git repository

Slide 37

Slide 37 text

Consumers and provider use the PACT broker to keep contracts and status up-to-date. 40 PACT broker Consumer 1 Consumer 2 Provider Retrieving the contract(s) Testing against the contract Writing the results Testing against the contract(s) The broker generated transparency for both consumers and provider. It also generates an overview about the dependencies of the application landscape.

Slide 38

Slide 38 text

The PACT broker makes the status of all contracts transparent 41

Slide 39

Slide 39 text

As soon as the contract is verified by the producer, the PACT broker indicates the validity 42

Slide 40

Slide 40 text

The PACT broker makes contract breaches by the provider transparent. 43

Slide 41

Slide 41 text

04 Summary

Slide 42

Slide 42 text

CDCT bridges the gap for Integration Testing CDCT helps: • Supports collaboration between teams and discussion of interfaces • Implements essential tests of interfaces (structure, naming, typing, response codes) • Speeds up development processes for both consumer and provider CDCT does not help: • Replacement for End2End Tests  use End2End Tests only where really necessary • Replacement for business logic tests  use Unit Tests instead • Testing against non-functional requirements Adoption from Consumer-driven Contracts, Markus Knittig (https://entwicklertag.de/karlsruhe/2018/sites/entwicklertag.de.karlsruhe.2018/files/folien/4.%20Consumer-Driven%20Contracts.pdf)

Slide 43

Slide 43 text

Contact Stephan Stapel [email protected] Our presentation deck: www.speakerdeck.com/hermes CDCT sample applications: https://github.com/HermesGermany/jug-cdc

Slide 44

Slide 44 text

No content