Contract Tests in the Enterprise

Marcin Grzejszczak, @mgrzejszczak

© 2018 Pivotal

1

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/

Just another day at work

3

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

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/

How our CI system looks like

5

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/

What’s our deployment strategy?

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 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 MONTHS

LAST 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/

How the code is currently tested

10

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

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/

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.

12

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!

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 tests FTW!

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/

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

15

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

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 tests FTW!

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/

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.

18

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!

19

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/

Speaking of End to End tests…
The Customer Rental History is unreliable

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/

Application Architecture

21

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

22

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

  • 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

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/

Problems with hard coding stubs

24

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?

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/

Let’s proxy the calls!

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/

Generating Stubs From Proxy

27

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

28

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?

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/

Testing Strategy - Generated Remote Stub

30

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

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/

OK, we’ve dealt with the app we don’t control. How about those we do control?

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/

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?

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/

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 predefined extension fields
  • Consumer-Driven Contracts

34

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

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/

Provider Contract

  • The implementer of a service defines the interface of the service everyone uses the same interface

36

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

37

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

38

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

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/

How the code should be tested

40

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

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/

Problem?
Our monolith is the source of truth

We don’t know if we can change its API

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/

Monolith as source of truth

43

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/

Consumers create stubs (current approach)

44

GET /user/

GET /user/

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

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/

Let’s try to solve this problem

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/

We need to define a contract somehow

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/

Example of a contract

48

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 the contract is valid

We want to build reliable stubs

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/

Generating Stubs & Tests (PRODUCER)

50

Stubs

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)

51

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)

52

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)

53

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)

54

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)

55

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

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/

OK, what about new, shiny microservices?

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/

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

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/

Consumer Driven Contracts

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/

There is no producer code!

60

CONSUMER

REPO WITH CONTRACTS

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!

61

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

62

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

63

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

64

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

65

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

66

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

67

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

68

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

69

CONSUMER

LET ME USE THE PRODUCER’S STUBS FOR MY TESTS

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/

Did you say, that ALL contracts
are stored in a single repo?

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/

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/

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/

What about messaging?

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

CONSUMER

PRODUCER

TEST

PRODUCER

CONSUMER

REALITY

topic: bar

topic: foo

topic: bar

topic: 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

77

(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?

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/

NodeJs app

79

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

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/

Polyglot

81

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

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/

Can I generate tests for an app
in any language?

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

84

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/

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/

What have we managed to build?

  • The implemented framework: Spring Cloud Contract (just released 2.0.0!!)
  • 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/

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/

Disclaimer Statement

The following is intended to outline the general direction of Pivotal's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of Pivotal offerings, future updates or other planned modifications is subject to ongoing evaluation by Pivotal and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding Pivotal's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for Pivotal's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation.

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/

mgrzejszczak

Contract Tests in the Enterprise @ Code'n'Quality 2018 - Google Slides