37
Commercial in Confidence | Assurity Consulting Limited 2014 Pact – Consumer Driven Contract Testing “Integrated Tests Are A Scam” Pete Sellars – Technical Consultant

Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Embed Size (px)

DESCRIPTION

Lightening Talk for the Auckland Continuous Delivery Meetup spreading the message that 'Integrated Tests Are A Scam', providing a journey to where we are and a focus on Pact as a tool to solve service 'integration' testing using Consumer-Driven Contracts.

Citation preview

Page 1: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact – Consumer Driven Contract Testing“Integrated Tests Are A Scam”

Pete Sellars – Technical Consultant

Page 2: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Challenge…

Page 3: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Who Writes Integration Test?

Page 4: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Integrated Tests Are A Scam

Integrated tests are a scam—a self-replicating virus that threatens to infect your code base, your project, and your team with endless pain and suffering.

Page 5: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Code Whisperer

Page 6: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Challenge Accepted

Page 7: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2005

Page 8: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Contract Tests – Design By Contract

Page 9: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2006

Page 10: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Contracts Overview

Provider• Closed & Complete• Singular & Authorative• Bounded Stability &

Immutability

Consumer• Open & Incomplete• Multiple & • Non-Authorative• Bounded Stability &

Immutability

Consumer-Driven• Closed & Complete• Singular & • Non-Authorative• Bounded Stability &

Immutability

Consumer-Driven Contracts, A Service Evolution Pattern: Ian Robinson

Page 11: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Consumer-Driven Contract Benefits

…they focus the specification and delivery of service

functionality around key business value drivers.

…give us the fine-grained insight and rapid feedback we require to plan changes and

assess their impact on applications currently in

production

Consumer-Driven Contracts, A Service Evolution Pattern: Ian Robinson

Page 12: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2009

Page 13: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Why Are Integrated Tests A Scam?

Page 14: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Why Are Integrated Tests A Scam

Integrated Tests Are A Scam (2009): J.B. Rainsberger

Page 15: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

How to beat the Scam….

Integrated Tests Are A Scam (2009): J.B. Rainsberger

Page 16: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2010

Page 17: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Why Are Integrated Tests A Scam?

Integrated Tests Are A Scam (2010): J.B. Rainsberger

Page 18: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Why Are Integrated Tests A Scam…

Consider 10 layers with 3 potential branch points

at each layer. Number of code paths: 310 > 59,000.

How about 4 branch points per layer? 410 >

1,000,000. How about 3 branch and 12 layers?

312 > 530,000.

How about 3 branch and 12 layers? 312 > 530,000.

Even if one of your 12 layers has a single code

path, 311 > 177,000.

Even if your 10-layer application has only an

average of 3.5 code paths per layer, 3.510>

275,0001.

Integrated Tests Are A Scam (2010): J.B. Rainsberger

Do you feel lucky? Do you?

Page 19: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

How to beat the Scam…

Integrated Tests Are A Scam (2010): J.B. Rainsberger

Page 20: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2010

Page 21: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Sharing Tests!! …

To reduce the chances of unexpected breaks in integration contracts, it's useful to move to a Consumer Driven Contracts

approach. You can facilitate this by letting the supplier team have copies of your

integration contract tests so they can run them as part of their build pipeline.

Integrtation Contract Tests (2010): Martin Fowler

Page 22: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

2010: Writing Consumer-Driven Contracts?

Page 23: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Micro Services

Page 24: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Micro Services

Page 25: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2013

Page 26: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact

Testing Interactions with Web Services without Integration Tests In Ruby:

REA Engineering Blog

Page 27: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact

Consumer sets up expectations on a mock service provider. Mock

service returns the expected responses.

The requests, and their expected responses, are then written to a "pact“

file

The requests in the pact file are later replayed

against the provider. Actual responses are checked to make sure they match the

expected responses.

Integrated Tests Are A Scam (2010): J.B. Rainsberger

Page 28: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact

Testing with Pact: Pact Wiki

Page 29: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact

Simplifying Micro-Services Testing with Pacts: Ron Holshausen

Page 30: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact Features

Pact Wiki

Page 31: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Pact

We now have fast unit-like tests on each side of the

integration point instead of tedious integration tests.

Testing Interactions with Web Services without Integration Tests In Ruby:

REA Engineering Blog

Page 32: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2013

Page 33: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Why Integration Test Are Still A Scam…

Integrated Tests Are A Scam

Doesn’t Provide

Coverage Expected

Encourage Sloppy Coding

Cumulative # Required;

Slow & Brittle

Page 34: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Timeline - 2014

Page 35: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Trial Pact & Pacto

Consumer-Driven Contracts are a testing approach to help service interfaces evolve

with confidence without unknowingly breaking consumers. The similarly named Pact

and Pacto are two new open-source tools which allow testing interactions between

service providers and consumers in isolation against a contract. Both have grown out of

projects which are building RESTful microservices and show great promise.

ThoughtWorks Technology Radar: July 2014

Page 36: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

Do Things Differently?

Page 37: Lightening Talk: Auckland Continuous Delivery Meetup [Sept 2014] - Pact: Consumer-Driven Contract Testing (Integrated Tests Are A Scam)

Commercial in Confidence | Assurity Consulting Limited 2014

References

• Blog Posts> Contract Testing, J.B. Rainsberger: http://blog.thecodewhisperer.com/2005/03/02/in-brief-contract-tests/> Integrated Tests Are A Scam, J.B. Rainsberger: http://blog.thecodewhisperer.com/2010/10/16/integrated-tests-are-a-scam/> IntegrationContractTests, Martin Fowler: http://martinfowler.com/bliki/IntegrationContractTest.html> Testing Interactions with WebServices without Integration Tests in Ruby, REA Techblog: http://techblog.realestate.com.au/testing-interactions-with-web-services-without-integration-tests-in-ruby/> Simplifying Micro-Service testing with Pacts, Ron Holshausen: http://dius.com.au/2014/05/19/simplifying-micro-service-testing-with-pacts/

• Articles> Consumer-Driven Contracts – A Service Evolution Pattern, Ian Robinson: http://www.martinfowler.com/articles/consumerDrivenContracts.html> Thoughtworks Technology Radar: http://www.thoughtworks.com/radar> Design By Contract: http://c2.com/cgi/wiki?DesignByContract

• Presentations> Agile 2009 - Integration Tests Are A Scam, J.B. Rainsberger: http://www.infoq.com/presentations/integration-tests-scam> Integration Tests Are A Scam (Slides 2010), J.B. Rainsberger: http://www.slideshare.net/agileee/notes-5407051> DevConFu 2013 – Integrated Tests Are A Scam, J.B. Rainsberger: http://vimeo.com/80533536> Micro-Service Architecture, Fred George: http://www.slideshare.net/fredgeorge/micro-service-architecure> Practical Microserices (YOW 2013), Sam Newman: http://www.slideshare.net/spnewman/practical-microservices-yow-2013> Practical Considerations for Micro-Service Architectures, Sam Newman: http://yow.eventer.com/yow-2013-1080/practical-considerations-for-microservice-architectures-by-sam-newman-1389

• Tools> Pact: https://github.com/realestate-com-au/pact/wiki

− Provider State Example: https://github.com/realestate-com-au/pact/blob/master/example/zoo-app/spec/service_providers/animal_service_client_spec.rb− Generated Documentation Example: https://github.com/realestate-com-au/pact/blob/master/example/zoo-app/doc/pacts/markdown/Zoo%20App%20-%20Animal%20Service.md

> Pacto: http://thoughtworks.github.io/pacto/