SlideShare une entreprise Scribd logo
1  sur  90
Télécharger pour lire hors ligne
1
© 2018 Pivotal
Contract Tests in the Enterprise
Marcin Grzejszczak, @mgrzejszczak
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
About me
Spring Cloud developer at Pivotal working mostly on
● Spring Cloud Sleuth
● Spring Cloud Contract
● Spring Cloud Pipelines
Connect with me
● Twitter: @mgrzejszczak
● Blog: http://toomuchcoding.com
2
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
#frameworkless
#backtothebasics
3
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Just another day at work
4
http://4.bp.blogspot.com/-6OK2CgfysNQ/U86JhcS_OKI/AAAAAAAAurI/O5lNezASrwo/s1600/10373729_294545550713169_1314239177487458186_n.jpg
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How the code is currently organized
5
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How our CI system looks like
6
https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.findbestopensource.com%
2FAppImages%2FArticle%2Fjenkins-img1.jpg&f=1
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How the code is currently deployed
7
https://www.process.st/business-process-modeling/
15 HOURS OF E2E
TESTS PLACE HERE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
We’re agile & we care about quality
8
THE SPRINT (6 MONTHS)
5 MONTHSLAST MONTH
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Application Architecture
9
Legacy
service
Customer Rental
History service
Payment
processor
Mainframe
Audit service
Insurance
service
● Interservice calls are over http
● Legacy service that is hard to test due the dependencies it
has on other downstream services
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What’s our testing strategy?
10
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How the code is currently tested
11
https://www.ontestautomation.com/wp-content/uploads/2014/06/pyramid_inverted.png
MANUAL TESTING
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
The testing pyramid...
12
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Unit Test
In computer programming, unit testing is a software testing method by which
individual units of source code, sets of one or more computer program
modules (...) are tested to determine whether they are fit for use.
13
Kolawa, Adam; Huizinga, Dorota (2007). Automated Defect Prevention: Best Practices in Software Management. Wiley-IEEE Computer Society Press. p. 75. ISBN 0-470-04212-5.
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Great! I’ll write unit tests only!
14
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Unit tests FTW!
15
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Integration Test
Integration testing (...) is the phase in software testing in which individual
software modules are combined and tested as a group. (...) Integration testing
takes as its input modules that have been unit tested, groups them in larger
aggregates, applies tests (...) and delivers as its output the integrated system
ready for system testing
16
Martyn A Ould & Charles Unwin (ed), Testing in Software Development, BCS (1986), p71.
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Ok I don’t need unit tests, I’ll write only
integration tests
17
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Integration tests FTW!
18
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
19
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
End to end Test
End-to-end testing involves ensuring that the integrated components of an
application function as expected. The entire application is tested in a real-world
scenario such as communicating with the database, network, hardware and other
applications.
20
https://www.techopedia.com/definition/7035/end-to-end-test
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
End to end tests FTW!
21
https://www.process.st/business-process-modeling/
15 HOURS OF E2E
TESTS PLACE HERE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
End to end tests FTW!
22
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Speaking of End to End tests…
The Customer Rental History is unreliable
23
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Application Architecture
24
Legacy
service
Customer Rental
History service
Payment
processor
Mainframe
Audit service
Insurance
service
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Testing Strategy - Hard Coded Object Stubs
25
Legacy
service
Customer Rental
History service
Payment
processor
Audit service
Insurance
service
Hard coded
Customer
Rental History
Service Stub Mainframe
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Problems with hard coding stubs
26
● 1225 line JSON response
● Hard to keep hard coded
stub in sync with the api
being stubbed
● Stub does not test that
requests are made
correctly to the remote
service
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Problems with hard coding stubs
27
Stubs that were used in the build phase have nothing to do with the real API!!
/foo
LEGACY APP
CUSTOMER
RENTAL
HISTORY
TEST
OK
/foo
LEGACY APP
CUSTOMER
RENTAL
HISTORY
REALITY
WAT?!
If /foo
respond
with OK
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How to create reliable stubs for services
we don’t control?
28
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Let’s proxy the calls!
29
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Generating Stubs From Proxy
30
Test that calls
Customer
Rental History
Service
Customer Rental
History Service
Payment
processor
Mainframe
PROXY
Record traffic and
dump stubs (e.g.
once per day)
Upload stubs for
other teams to use
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Stubs From Proxy
31
Given this
request
Send back
this
response
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Now that we have stubs,
how can we test the system?
32
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Testing Strategy - Generated Remote Stub
33
Legacy
service
Customer Rental
History Service
Payment
processor
Customer Rental
History Service Stub
from the proxy
Legacy service
integration test
Mainframe
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Outcome?
Fast feedback from quite reliable stubs
Less money spent on e2e
34
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
OK, we’ve dealt with the app we don’t control.
How about those we do control?
35
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Hard Problems
● How can something be added to a service without breaking the clients?
● How can something be removed from a service without breaking the clients?
● How can a service developer find out how clients are using their service?
● How to enable short release cycles and continuous delivery of services?
36
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Service Evolution Patterns
● Tolerant Reader
○ Extract only what is needed, ignore unknown content
● Schema Versioning
○ Put Schema versions in the API url / headers (v1, v2)
● Extension Points
○ Additional, optional data structured in a predefined extension field
● Consumer-Driven Contracts
37
http://servicedesignpatterns.com/WebServiceEvolution
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Definitions
● Producer
○ service that exposes an API / sends a message
● Consumer
○ service that consumes the API of the producer /
listens to a message from the producer
● Contract
○ agreement between producer and consumer how the API /
message will look like
38
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Provider Contract
• The implementer of a service defines the interface of the
service everyone uses the same interface
39
Service
Client A
Client B
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Consumer Contract
● The consumer of a service defines their interface to the service within the
conventions / spirit of provider contract
40
Service
Client A
Client B
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Consumer Driven Contracts
41
Source: http://martinfowler.com/articles/consumerDrivenContracts.html
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Benefits of Consumer Driven Contracts
● Align service providers with the business goals of their consumer through the
consumer driven contracts
● Provide insights into how a service is being used by its consumers
● Make evolving services easier by reducing the amount of coordination
required to evolve interfaces
● Help in the configuration of continuous delivery pipelines
42
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
How the code should be tested
43
UNIT TESTS
SERVICE, API,
CONTRACT
TESTS
E2E, UI
TESTS
MANUAL
TESTS
MANUAL TESTING
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Migrating to microservices...
44
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Problem?
Our monolith is the source of truth
We don’t know if we can change its API
45
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Monolith as source of truth
46
Legacy
service
Audit service
Insurance
service
Ledger
service
Payment
service
Invoice
service
Warehouse
service
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
GET /user/GET /user/
Consumers create stubs (current approach)
47
Legacy
service
GET /user/Audit service
Insurance
service
Ledger
service
Payment
service
Invoice
service
Warehouse
service
GET /user/
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Problem?
Stubs on the consumer side not reliable
Time wasted on writing the same stubs
48
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Let’s write a Segfault Contract contract
testing framework!
#frameworkless
49
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
We need to define a contract somehow
50
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Example of a contract
51
Given this
request
Send back
this
response
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
We need to assert that contract is valid
We want to build reliable stubs
52
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Stubs
Generating Stubs & Tests (PRODUCER)
53
Legacy
service
Customer Rental
History Service
Payment
processor
Mainframe
Audit service
Insurance
service
Contract
Tests
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Generating Stubs & Tests (PRODUCER)
54
Generate reusable
stubs
Read
Run tests to verify
if contract is met
Run build
$ build project
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Contract Tests (PRODUCER)
55
Given this
request
Is the
response
correct ?
Send the
request
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Generated Stubs (PRODUCER)
56
Given this
request
Send back
this
response
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Monolith as source of truth (better approach)
57
GET
/user/
Legacy
service
POST
/user/
Audit service
Insurance
service
Ledger
service
Payment
service
Invoice
service
Warehouse
service
STUB
STORAGE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Reuse Stubs (CONSUMER)
58
Fetch stubs & run
stub servers
Consumer tests
Test
runner
Fetch stubs
STUB
STORAGE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Outcome?
Fast feedback from reliable stubs (fail fast)
Less money spent on e2e
Less time wasted on duplicating stubs
59
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
OK, what about new, shiny microservices?
60
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Nice API creation
● It’s the consumer that uses the API
● Consumers should take part in the creation of the API of the producer
● The producer’s API change should be driven by consumers
61
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Consumer Driven Contracts
62
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
There is no producer code!
63
CONSUMER
REPO WITH
CONTRACTS
INTERACTION
I THINK I LIKE THIS API
EVEN THOUGH THE
PRODUCER DOESN’T
EVEN EXIST!
WHAT IF I
CALLED THE
API LIKE THIS...
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Store the stubs from contracts locally
64
CONSUMER
REPO WITH
CONTRACTS
INTERACTION
LOCAL STORAGE
WITH STUBS
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Play with the API offline
65
CONSUMER
REPO WITH
CONTRACTS
TESTS
LOCAL STORAGE
WITH STUBS
FROM
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
File a PR
66
CONSUMER
REPO WITH
CONTRACTS
YUP, I LIKE IT!
TIME FOR A PR
PR
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Producer sets up a project
67
PRODUCER
REPO WITH
CONTRACTS
INTRACTION
OH, SOMEONE HAS
REQUESTED THAT
I HAVE SUCH API...
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Producer sets up a project
68
PRODUCER
REPO WITH
CONTRACTS
INTRACTION
THE TESTS ARE
FAILING… NO
WONDER, I HAVE
NO CODE :|
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Producer makes the generated tests pass
69
PRODUCER
REPO WITH
CONTRACTS
PR
OK, THE TESTS
ARE PASSING, LET
ME MERGE THE PR
TO MASTER
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
CI server builds the producer code
70
PRODUCER
BUILD
UPLOAD
BINARY
UPLOAD
STUBS
STUB
STORAGE
BINARY
STORAGE
CI SYSTEM
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Consumer uses uploaded stubs
71
CONSUMER
LET ME USE THE
PRODUCER’S
STUBS FOR MY
TESTS
FETCHSTUBS
STUB
STORAGE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Did you say, that ALL contracts
are stored in a single repo?
72
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
73
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
74
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
75
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
76
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What about messaging?
77
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
78
CONSUMERPRODUCER
TEST
PRODUCER CONSUMER
REALITY
topic: bar topic: foo
topic: bartopic: foo
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Messaging
79
(PRODUCER) Do I
trigger the message?
(PRODUCER) Is it sent
to a proper destination?
(PRODUCER) Can I
serialize it properly?
(CONSUMER) Do I
listen at a proper
destination?
(CONSUMER) Can I
deserialize it properly?
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What about polyglot support?
80
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
NodeJs app
81
https://github.com/marcingrzejszczak/sc-contract-car-rental
NodeJs
Some HTTP
service
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Doesn’t work
82
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Polyglot
83
Non JVM app
Send a request
Stub will respond
RUN
STUB
STORAGE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
NodeJs works
84
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Can I generate tests for an app
in any language?
85
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Polyglot
86
contract1.yml
GET
/user/
App
contract2.yml
POST
/user/
Contracts mounted
to generate tests
and stubs
Tests executed
from the container
against a running
app
RUN
STUB
STORAGE
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
87
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
● The implemented framework: Spring Cloud Contract
● The stub server: WireMock
● Available DSLs: Groovy, YAML
● Supports:
○ messaging (Spring Cloud Stream, Spring Integration, Spring AMQP, whatever you want)
○ dynamic pieces
○ resolution of request from response
○ stateful stubs (stubs have memory)
○ you can store stubs in Git, Nexus / Artifactory, Pact Broker
● And much, much more…
● Read the docs: http://cloud.spring.io/spring-cloud-contract/
What have we managed to build?
88
#frameworkless
Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Disclaimer Statement
89
mgrzejszczak

Contenu connexe

Tendances

Progressive Deployment & NoDeploy
Progressive Deployment & NoDeployProgressive Deployment & NoDeploy
Progressive Deployment & NoDeployYi-Feng Tzeng
 
Dev(Sec)Ops - Architecture for Security and Compliance
Dev(Sec)Ops - Architecture for Security and ComplianceDev(Sec)Ops - Architecture for Security and Compliance
Dev(Sec)Ops - Architecture for Security and ComplianceYi-Feng Tzeng
 
ChromeとAndroidの過去・現在・未来
ChromeとAndroidの過去・現在・未来ChromeとAndroidの過去・現在・未来
ChromeとAndroidの過去・現在・未来Shinobu Okano
 
Architectures That Bend but Don't Break
Architectures That Bend but Don't BreakArchitectures That Bend but Don't Break
Architectures That Bend but Don't BreakMatt Stine
 
Spring Cloud Kubernetes - Ryan Baxter
Spring Cloud Kubernetes - Ryan BaxterSpring Cloud Kubernetes - Ryan Baxter
Spring Cloud Kubernetes - Ryan BaxterVMware Tanzu
 
Know Your Users: Improving Learning Content by Connecting with Users
Know Your Users: Improving Learning Content by Connecting with UsersKnow Your Users: Improving Learning Content by Connecting with Users
Know Your Users: Improving Learning Content by Connecting with Userspatricia_gale
 

Tendances (6)

Progressive Deployment & NoDeploy
Progressive Deployment & NoDeployProgressive Deployment & NoDeploy
Progressive Deployment & NoDeploy
 
Dev(Sec)Ops - Architecture for Security and Compliance
Dev(Sec)Ops - Architecture for Security and ComplianceDev(Sec)Ops - Architecture for Security and Compliance
Dev(Sec)Ops - Architecture for Security and Compliance
 
ChromeとAndroidの過去・現在・未来
ChromeとAndroidの過去・現在・未来ChromeとAndroidの過去・現在・未来
ChromeとAndroidの過去・現在・未来
 
Architectures That Bend but Don't Break
Architectures That Bend but Don't BreakArchitectures That Bend but Don't Break
Architectures That Bend but Don't Break
 
Spring Cloud Kubernetes - Ryan Baxter
Spring Cloud Kubernetes - Ryan BaxterSpring Cloud Kubernetes - Ryan Baxter
Spring Cloud Kubernetes - Ryan Baxter
 
Know Your Users: Improving Learning Content by Connecting with Users
Know Your Users: Improving Learning Content by Connecting with UsersKnow Your Users: Improving Learning Content by Connecting with Users
Know Your Users: Improving Learning Content by Connecting with Users
 

Similaire à Marcin Grzejszczak - Contract Tests in the Enterprise

Extending the Platform
Extending the PlatformExtending the Platform
Extending the PlatformVMware Tanzu
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureMarcin Grzejszczak
 
Extending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud FoundryExtending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud FoundryKenny Bastani
 
Tools to Slay the Fire Breathing Monoliths in Your Enterprise
Tools to Slay the Fire Breathing Monoliths in Your EnterpriseTools to Slay the Fire Breathing Monoliths in Your Enterprise
Tools to Slay the Fire Breathing Monoliths in Your EnterpriseVMware Tanzu
 
Architectures That Bend But Don't Break
Architectures That Bend But Don't BreakArchitectures That Bend But Don't Break
Architectures That Bend But Don't BreakVMware Tanzu
 
Cloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud ServicesCloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud ServicesVMware Tanzu
 
Managing the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsManaging the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsVMware Tanzu
 
Containers Were Never Your End State
Containers Were Never Your End StateContainers Were Never Your End State
Containers Were Never Your End StateVMware Tanzu
 
Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)VMware Tanzu
 
P to V to C: The Value of Bringing “Everything” to Containers
P to V to C: The Value of Bringing “Everything” to ContainersP to V to C: The Value of Bringing “Everything” to Containers
P to V to C: The Value of Bringing “Everything” to ContainersVMware Tanzu
 
Experience + Education = Empowerment
Experience + Education = EmpowermentExperience + Education = Empowerment
Experience + Education = EmpowermentVMware Tanzu
 
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...VMware Tanzu
 
Healthy Agile Product Security
Healthy Agile Product SecurityHealthy Agile Product Security
Healthy Agile Product SecurityVMware Tanzu
 
Spring Cloud Gateway - Ryan Baxter
Spring Cloud Gateway - Ryan BaxterSpring Cloud Gateway - Ryan Baxter
Spring Cloud Gateway - Ryan BaxterVMware Tanzu
 
Lattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsLattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsMatt Stine
 
Spring Cloud Gateway - Stéphane Maldini
Spring Cloud Gateway - Stéphane MaldiniSpring Cloud Gateway - Stéphane Maldini
Spring Cloud Gateway - Stéphane MaldiniVMware Tanzu
 
Fast 5 Things You Can Do Now to Get Ready for the Cloud
Fast 5 Things You Can Do Now to Get Ready for the CloudFast 5 Things You Can Do Now to Get Ready for the Cloud
Fast 5 Things You Can Do Now to Get Ready for the CloudVMware Tanzu
 
Accelerating the Developers' Road to the Cloud at Enterprise Scale
Accelerating the Developers' Road to the Cloud at Enterprise ScaleAccelerating the Developers' Road to the Cloud at Enterprise Scale
Accelerating the Developers' Road to the Cloud at Enterprise ScaleVMware Tanzu
 

Similaire à Marcin Grzejszczak - Contract Tests in the Enterprise (20)

Extending the Platform
Extending the PlatformExtending the Platform
Extending the Platform
 
Consumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice ArchitectureConsumer Driven Contracts and Your Microservice Architecture
Consumer Driven Contracts and Your Microservice Architecture
 
Extending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud FoundryExtending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud Foundry
 
Tools to Slay the Fire Breathing Monoliths in Your Enterprise
Tools to Slay the Fire Breathing Monoliths in Your EnterpriseTools to Slay the Fire Breathing Monoliths in Your Enterprise
Tools to Slay the Fire Breathing Monoliths in Your Enterprise
 
Architectures That Bend But Don't Break
Architectures That Bend But Don't BreakArchitectures That Bend But Don't Break
Architectures That Bend But Don't Break
 
Cloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud ServicesCloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud Services
 
Managing the Complexity of Microservices Deployments
Managing the Complexity of Microservices DeploymentsManaging the Complexity of Microservices Deployments
Managing the Complexity of Microservices Deployments
 
Containers Were Never Your End State
Containers Were Never Your End StateContainers Were Never Your End State
Containers Were Never Your End State
 
Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)Under the Hood of Reactive Data Access (2/2)
Under the Hood of Reactive Data Access (2/2)
 
P to V to C: The Value of Bringing “Everything” to Containers
P to V to C: The Value of Bringing “Everything” to ContainersP to V to C: The Value of Bringing “Everything” to Containers
P to V to C: The Value of Bringing “Everything” to Containers
 
Experience + Education = Empowerment
Experience + Education = EmpowermentExperience + Education = Empowerment
Experience + Education = Empowerment
 
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...
Continuous Delivery for Microservice Architectures with Concourse & Cloud Fou...
 
Zuul @ Netflix SpringOne Platform
Zuul @ Netflix SpringOne PlatformZuul @ Netflix SpringOne Platform
Zuul @ Netflix SpringOne Platform
 
Healthy Agile Product Security
Healthy Agile Product SecurityHealthy Agile Product Security
Healthy Agile Product Security
 
Spring Cloud Gateway
Spring Cloud GatewaySpring Cloud Gateway
Spring Cloud Gateway
 
Spring Cloud Gateway - Ryan Baxter
Spring Cloud Gateway - Ryan BaxterSpring Cloud Gateway - Ryan Baxter
Spring Cloud Gateway - Ryan Baxter
 
Lattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsLattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring Applications
 
Spring Cloud Gateway - Stéphane Maldini
Spring Cloud Gateway - Stéphane MaldiniSpring Cloud Gateway - Stéphane Maldini
Spring Cloud Gateway - Stéphane Maldini
 
Fast 5 Things You Can Do Now to Get Ready for the Cloud
Fast 5 Things You Can Do Now to Get Ready for the CloudFast 5 Things You Can Do Now to Get Ready for the Cloud
Fast 5 Things You Can Do Now to Get Ready for the Cloud
 
Accelerating the Developers' Road to the Cloud at Enterprise Scale
Accelerating the Developers' Road to the Cloud at Enterprise ScaleAccelerating the Developers' Road to the Cloud at Enterprise Scale
Accelerating the Developers' Road to the Cloud at Enterprise Scale
 

Plus de SegFaultConf

Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonych
Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonychWojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonych
Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonychSegFaultConf
 
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemTomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemSegFaultConf
 
Zbyszko Papierski - Communication patterns in carbon-based networks
Zbyszko Papierski - Communication patterns in carbon-based networksZbyszko Papierski - Communication patterns in carbon-based networks
Zbyszko Papierski - Communication patterns in carbon-based networksSegFaultConf
 
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka fala
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka falaDaniel Pokusa - Praca z kodem zastanym- nadchodzi wielka fala
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka falaSegFaultConf
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?SegFaultConf
 
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknę
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknęDominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknę
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknęSegFaultConf
 
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temu
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temuKrzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temu
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temuSegFaultConf
 
Jan Pustelnik - Curry-Howard w praktyce
Jan Pustelnik - Curry-Howard w praktyceJan Pustelnik - Curry-Howard w praktyce
Jan Pustelnik - Curry-Howard w praktyceSegFaultConf
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?SegFaultConf
 

Plus de SegFaultConf (9)

Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonych
Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonychWojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonych
Wojciech Rząsa - Przewidywanie zmian wydajności aplikacji rozproszonych
 
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemTomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
 
Zbyszko Papierski - Communication patterns in carbon-based networks
Zbyszko Papierski - Communication patterns in carbon-based networksZbyszko Papierski - Communication patterns in carbon-based networks
Zbyszko Papierski - Communication patterns in carbon-based networks
 
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka fala
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka falaDaniel Pokusa - Praca z kodem zastanym- nadchodzi wielka fala
Daniel Pokusa - Praca z kodem zastanym- nadchodzi wielka fala
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
 
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknę
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknęDominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknę
Dominik Boszko - Krocząc doliną ciemności mikroserwisów się nie ulęknę
 
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temu
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temuKrzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temu
Krzysztof Kaczmarek - 10 rzeczy, które chciałbym wiedzieć 10 lat temu
 
Jan Pustelnik - Curry-Howard w praktyce
Jan Pustelnik - Curry-Howard w praktyceJan Pustelnik - Curry-Howard w praktyce
Jan Pustelnik - Curry-Howard w praktyce
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
 

Dernier

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Dernier (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Marcin Grzejszczak - Contract Tests in the Enterprise

  • 1. 1 © 2018 Pivotal Contract Tests in the Enterprise Marcin Grzejszczak, @mgrzejszczak
  • 2. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About me Spring Cloud developer at Pivotal working mostly on ● Spring Cloud Sleuth ● Spring Cloud Contract ● Spring Cloud Pipelines Connect with me ● Twitter: @mgrzejszczak ● Blog: http://toomuchcoding.com 2
  • 3. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ #frameworkless #backtothebasics 3
  • 4. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Just another day at work 4 http://4.bp.blogspot.com/-6OK2CgfysNQ/U86JhcS_OKI/AAAAAAAAurI/O5lNezASrwo/s1600/10373729_294545550713169_1314239177487458186_n.jpg
  • 5. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently organized 5
  • 6. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How our CI system looks like 6 https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.findbestopensource.com% 2FAppImages%2FArticle%2Fjenkins-img1.jpg&f=1
  • 7. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently deployed 7 https://www.process.st/business-process-modeling/ 15 HOURS OF E2E TESTS PLACE HERE
  • 8. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We’re agile & we care about quality 8 THE SPRINT (6 MONTHS) 5 MONTHSLAST MONTH
  • 9. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Architecture 9 Legacy service Customer Rental History service Payment processor Mainframe Audit service Insurance service ● Interservice calls are over http ● Legacy service that is hard to test due the dependencies it has on other downstream services
  • 10. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s our testing strategy? 10
  • 11. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently tested 11 https://www.ontestautomation.com/wp-content/uploads/2014/06/pyramid_inverted.png MANUAL TESTING
  • 12. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The testing pyramid... 12
  • 13. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Unit Test In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules (...) are tested to determine whether they are fit for use. 13 Kolawa, Adam; Huizinga, Dorota (2007). Automated Defect Prevention: Best Practices in Software Management. Wiley-IEEE Computer Society Press. p. 75. ISBN 0-470-04212-5.
  • 14. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Great! I’ll write unit tests only! 14
  • 15. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Unit tests FTW! 15
  • 16. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Integration Test Integration testing (...) is the phase in software testing in which individual software modules are combined and tested as a group. (...) Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests (...) and delivers as its output the integrated system ready for system testing 16 Martyn A Ould & Charles Unwin (ed), Testing in Software Development, BCS (1986), p71.
  • 17. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Ok I don’t need unit tests, I’ll write only integration tests 17
  • 18. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Integration tests FTW! 18
  • 19. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19
  • 20. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end Test End-to-end testing involves ensuring that the integrated components of an application function as expected. The entire application is tested in a real-world scenario such as communicating with the database, network, hardware and other applications. 20 https://www.techopedia.com/definition/7035/end-to-end-test
  • 21. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end tests FTW! 21 https://www.process.st/business-process-modeling/ 15 HOURS OF E2E TESTS PLACE HERE
  • 22. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end tests FTW! 22
  • 23. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Speaking of End to End tests… The Customer Rental History is unreliable 23
  • 24. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Architecture 24 Legacy service Customer Rental History service Payment processor Mainframe Audit service Insurance service
  • 25. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Testing Strategy - Hard Coded Object Stubs 25 Legacy service Customer Rental History service Payment processor Audit service Insurance service Hard coded Customer Rental History Service Stub Mainframe
  • 26. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problems with hard coding stubs 26 ● 1225 line JSON response ● Hard to keep hard coded stub in sync with the api being stubbed ● Stub does not test that requests are made correctly to the remote service
  • 27. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problems with hard coding stubs 27 Stubs that were used in the build phase have nothing to do with the real API!! /foo LEGACY APP CUSTOMER RENTAL HISTORY TEST OK /foo LEGACY APP CUSTOMER RENTAL HISTORY REALITY WAT?! If /foo respond with OK
  • 28. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How to create reliable stubs for services we don’t control? 28
  • 29. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let’s proxy the calls! 29
  • 30. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generating Stubs From Proxy 30 Test that calls Customer Rental History Service Customer Rental History Service Payment processor Mainframe PROXY Record traffic and dump stubs (e.g. once per day) Upload stubs for other teams to use
  • 31. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Stubs From Proxy 31 Given this request Send back this response
  • 32. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Now that we have stubs, how can we test the system? 32
  • 33. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Testing Strategy - Generated Remote Stub 33 Legacy service Customer Rental History Service Payment processor Customer Rental History Service Stub from the proxy Legacy service integration test Mainframe
  • 34. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outcome? Fast feedback from quite reliable stubs Less money spent on e2e 34
  • 35. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ OK, we’ve dealt with the app we don’t control. How about those we do control? 35
  • 36. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hard Problems ● How can something be added to a service without breaking the clients? ● How can something be removed from a service without breaking the clients? ● How can a service developer find out how clients are using their service? ● How to enable short release cycles and continuous delivery of services? 36
  • 37. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Service Evolution Patterns ● Tolerant Reader ○ Extract only what is needed, ignore unknown content ● Schema Versioning ○ Put Schema versions in the API url / headers (v1, v2) ● Extension Points ○ Additional, optional data structured in a predefined extension field ● Consumer-Driven Contracts 37 http://servicedesignpatterns.com/WebServiceEvolution
  • 38. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Definitions ● Producer ○ service that exposes an API / sends a message ● Consumer ○ service that consumes the API of the producer / listens to a message from the producer ● Contract ○ agreement between producer and consumer how the API / message will look like 38
  • 39. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Provider Contract • The implementer of a service defines the interface of the service everyone uses the same interface 39 Service Client A Client B
  • 40. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Contract ● The consumer of a service defines their interface to the service within the conventions / spirit of provider contract 40 Service Client A Client B
  • 41. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Driven Contracts 41 Source: http://martinfowler.com/articles/consumerDrivenContracts.html
  • 42. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Benefits of Consumer Driven Contracts ● Align service providers with the business goals of their consumer through the consumer driven contracts ● Provide insights into how a service is being used by its consumers ● Make evolving services easier by reducing the amount of coordination required to evolve interfaces ● Help in the configuration of continuous delivery pipelines 42
  • 43. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code should be tested 43 UNIT TESTS SERVICE, API, CONTRACT TESTS E2E, UI TESTS MANUAL TESTS MANUAL TESTING
  • 44. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating to microservices... 44
  • 45. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problem? Our monolith is the source of truth We don’t know if we can change its API 45
  • 46. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith as source of truth 46 Legacy service Audit service Insurance service Ledger service Payment service Invoice service Warehouse service
  • 47. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GET /user/GET /user/ Consumers create stubs (current approach) 47 Legacy service GET /user/Audit service Insurance service Ledger service Payment service Invoice service Warehouse service GET /user/
  • 48. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problem? Stubs on the consumer side not reliable Time wasted on writing the same stubs 48
  • 49. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let’s write a Segfault Contract contract testing framework! #frameworkless 49
  • 50. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need to define a contract somehow 50
  • 51. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example of a contract 51 Given this request Send back this response
  • 52. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need to assert that contract is valid We want to build reliable stubs 52
  • 53. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Stubs Generating Stubs & Tests (PRODUCER) 53 Legacy service Customer Rental History Service Payment processor Mainframe Audit service Insurance service Contract Tests
  • 54. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generating Stubs & Tests (PRODUCER) 54 Generate reusable stubs Read Run tests to verify if contract is met Run build $ build project
  • 55. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Contract Tests (PRODUCER) 55 Given this request Is the response correct ? Send the request
  • 56. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generated Stubs (PRODUCER) 56 Given this request Send back this response
  • 57. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith as source of truth (better approach) 57 GET /user/ Legacy service POST /user/ Audit service Insurance service Ledger service Payment service Invoice service Warehouse service STUB STORAGE
  • 58. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reuse Stubs (CONSUMER) 58 Fetch stubs & run stub servers Consumer tests Test runner Fetch stubs STUB STORAGE
  • 59. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outcome? Fast feedback from reliable stubs (fail fast) Less money spent on e2e Less time wasted on duplicating stubs 59
  • 60. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ OK, what about new, shiny microservices? 60
  • 61. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Nice API creation ● It’s the consumer that uses the API ● Consumers should take part in the creation of the API of the producer ● The producer’s API change should be driven by consumers 61
  • 62. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Driven Contracts 62
  • 63. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ There is no producer code! 63 CONSUMER REPO WITH CONTRACTS INTERACTION I THINK I LIKE THIS API EVEN THOUGH THE PRODUCER DOESN’T EVEN EXIST! WHAT IF I CALLED THE API LIKE THIS...
  • 64. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Store the stubs from contracts locally 64 CONSUMER REPO WITH CONTRACTS INTERACTION LOCAL STORAGE WITH STUBS
  • 65. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Play with the API offline 65 CONSUMER REPO WITH CONTRACTS TESTS LOCAL STORAGE WITH STUBS FROM
  • 66. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ File a PR 66 CONSUMER REPO WITH CONTRACTS YUP, I LIKE IT! TIME FOR A PR PR
  • 67. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer sets up a project 67 PRODUCER REPO WITH CONTRACTS INTRACTION OH, SOMEONE HAS REQUESTED THAT I HAVE SUCH API...
  • 68. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer sets up a project 68 PRODUCER REPO WITH CONTRACTS INTRACTION THE TESTS ARE FAILING… NO WONDER, I HAVE NO CODE :|
  • 69. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer makes the generated tests pass 69 PRODUCER REPO WITH CONTRACTS PR OK, THE TESTS ARE PASSING, LET ME MERGE THE PR TO MASTER
  • 70. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CI server builds the producer code 70 PRODUCER BUILD UPLOAD BINARY UPLOAD STUBS STUB STORAGE BINARY STORAGE CI SYSTEM
  • 71. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer uses uploaded stubs 71 CONSUMER LET ME USE THE PRODUCER’S STUBS FOR MY TESTS FETCHSTUBS STUB STORAGE
  • 72. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Did you say, that ALL contracts are stored in a single repo? 72
  • 73. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 73
  • 74. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 74
  • 75. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 75
  • 76. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 76
  • 77. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What about messaging? 77
  • 78. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 78 CONSUMERPRODUCER TEST PRODUCER CONSUMER REALITY topic: bar topic: foo topic: bartopic: foo
  • 79. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Messaging 79 (PRODUCER) Do I trigger the message? (PRODUCER) Is it sent to a proper destination? (PRODUCER) Can I serialize it properly? (CONSUMER) Do I listen at a proper destination? (CONSUMER) Can I deserialize it properly?
  • 80. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What about polyglot support? 80
  • 81. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ NodeJs app 81 https://github.com/marcingrzejszczak/sc-contract-car-rental NodeJs Some HTTP service
  • 82. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Doesn’t work 82
  • 83. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Polyglot 83 Non JVM app Send a request Stub will respond RUN STUB STORAGE
  • 84. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ NodeJs works 84
  • 85. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Can I generate tests for an app in any language? 85
  • 86. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Polyglot 86 contract1.yml GET /user/ App contract2.yml POST /user/ Contracts mounted to generate tests and stubs Tests executed from the container against a running app RUN STUB STORAGE
  • 87. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 87
  • 88. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ● The implemented framework: Spring Cloud Contract ● The stub server: WireMock ● Available DSLs: Groovy, YAML ● Supports: ○ messaging (Spring Cloud Stream, Spring Integration, Spring AMQP, whatever you want) ○ dynamic pieces ○ resolution of request from response ○ stateful stubs (stubs have memory) ○ you can store stubs in Git, Nexus / Artifactory, Pact Broker ● And much, much more… ● Read the docs: http://cloud.spring.io/spring-cloud-contract/ What have we managed to build? 88 #frameworkless
  • 89. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Disclaimer Statement 89