Transcript
Page 1: Behaviour driven infrastructure

BehaviourDriven

InfrastructureLindsay Holmwood

Page 2: Behaviour driven infrastructure

DevOps

Page 3: Behaviour driven infrastructure

Behaviour Driven

Development

Page 4: Behaviour driven infrastructure

Behaviour Driven

Infrastructure?

Page 5: Behaviour driven infrastructure

What is a behavioural test?

Page 6: Behaviour driven infrastructure

origins

Page 7: Behaviour driven infrastructure

Test Driven Development

Page 8: Behaviour driven infrastructure

write test

Page 9: Behaviour driven infrastructure

write testrun test

Page 10: Behaviour driven infrastructure

write testrun test

test fails

Page 11: Behaviour driven infrastructure

write testrun test

test fails

make test pass

Page 12: Behaviour driven infrastructure

write testrun test

test fails

make test pass

refactor

Page 13: Behaviour driven infrastructure

unit tests

Page 14: Behaviour driven infrastructure

input/outputof

functions

Page 15: Behaviour driven infrastructure

result = bar(foo)assert(result, true)

Page 16: Behaviour driven infrastructure

xUnit

Page 17: Behaviour driven infrastructure
Page 18: Behaviour driven infrastructure

a reaction to test focus

Behavior Driven Development

Page 19: Behaviour driven infrastructure

testing the

flow of data in a system

testing the

flow of data in a system

Page 20: Behaviour driven infrastructure

test auser canperform atask

Page 21: Behaviour driven infrastructure

make a donationsearch for productcheckout cart

Page 22: Behaviour driven infrastructure

verifying a business’sfunctional

requirementsare met

Page 23: Behaviour driven infrastructure

underlying

implementation isirrelevant

to the business

underlying

implementation isirrelevant

to the business

Page 24: Behaviour driven infrastructure

Business: “assert(bar(foo),true)?”Tech: “Yes”Business: “Great”

Page 25: Behaviour driven infrastructure

Business: “assert(bar(foo),true)?”Tech: “Yes”Business: “Great”

Page 26: Behaviour driven infrastructure

Business: “Can I search for things?”Tech: “Yes”Business: “Great”

Page 27: Behaviour driven infrastructure

functionis importantfunctionis important

Page 28: Behaviour driven infrastructure

implementationis not

implementationis not

Page 29: Behaviour driven infrastructure
Page 30: Behaviour driven infrastructure

verifying a business’sfunctional

requirementsare met

Page 31: Behaviour driven infrastructure

integration testsacceptance testsintegration testsacceptance tests

Page 32: Behaviour driven infrastructure

“outside-in tests”“outside-in tests”

Page 33: Behaviour driven infrastructure

executable specificationexecutable specification

Page 34: Behaviour driven infrastructure

written in

spoken languagewritten in

spoken language

Page 35: Behaviour driven infrastructure

so the business understands what it is

paying for

so the business understands what it is

paying for

Page 36: Behaviour driven infrastructure
Page 37: Behaviour driven infrastructure

Enough business touchy-feely mumbo

jumbo!

Page 38: Behaviour driven infrastructure

I thought this was a

Behaviour Driven

Infrastructure talk?

Page 39: Behaviour driven infrastructure

I thought this was a

Behaviour Driven

Infrastructure talk?

Page 40: Behaviour driven infrastructure
Page 41: Behaviour driven infrastructure

Infrastructure as code

Page 42: Behaviour driven infrastructure

“The ‘Infrastructure’ is an application, a long running process with inputs, outputs and state.”

- Andrew Schafer, 2009http://bit.ly/he3HBt

Page 43: Behaviour driven infrastructure

an abstractionan abstraction

Page 44: Behaviour driven infrastructure

infrastructureis the

application

Page 45: Behaviour driven infrastructure

daemonsare the

libraries

Page 46: Behaviour driven infrastructure

configuration managementis the

programming language

Page 47: Behaviour driven infrastructure

infrastructureis

built with code

Page 48: Behaviour driven infrastructure

code without testsis

bad

Page 49: Behaviour driven infrastructure

code without testsis

evilevil

Page 50: Behaviour driven infrastructure

Why?

Page 51: Behaviour driven infrastructure

You can’t verify that your system works.

Page 52: Behaviour driven infrastructure
Page 53: Behaviour driven infrastructure

Behaviour Driven

Infrastructure

Page 54: Behaviour driven infrastructure

Taking BDD

principals & tools

Taking BDD

principals & tools

Page 55: Behaviour driven infrastructure

Adapting them to

infrastructure development

Page 56: Behaviour driven infrastructure
Page 57: Behaviour driven infrastructure

Show me the

tools!

Page 58: Behaviour driven infrastructure

Cucumber

Page 59: Behaviour driven infrastructure

Executable format for software specifications

Page 60: Behaviour driven infrastructure

Tool to execute that specification

Page 61: Behaviour driven infrastructure
Page 62: Behaviour driven infrastructure

Terminology

Page 63: Behaviour driven infrastructure

featureis a

module of common functionality

Page 64: Behaviour driven infrastructure

Feature: Google search To increase her knowledge A user Needs a search interface To discover information

Page 65: Behaviour driven infrastructure

featurehas many

scenarios

Page 66: Behaviour driven infrastructure

Feature: Google search To increase her knowledge A user Needs a search interface To discover information

Scenario: Home page When I visit "http://google.com.au/" And I fill in "q" with "great balls of fire" Then I should see "great balls of fire"

Page 67: Behaviour driven infrastructure

scenariohas many

steps

Page 68: Behaviour driven infrastructure

Given

Page 69: Behaviour driven infrastructure

When

Page 70: Behaviour driven infrastructure

Then

Page 71: Behaviour driven infrastructure

And*

Page 72: Behaviour driven infrastructure
Page 73: Behaviour driven infrastructure

stepsare like

unit tests

Page 74: Behaviour driven infrastructure

they mapto

blocks of code

Page 75: Behaviour driven infrastructure

Feature: Google search To increase her knowledge A user Needs a search interface To discover information

Scenario: Home page When I visit "http://google.com.au/" And I fill in "q" with "great balls of fire" Then I should see "great balls of fire"

Page 76: Behaviour driven infrastructure

When /^I visit "([^"]*)"$/ do |location| # codeend

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |input, value| # codeend

Then /^I should see "([^"]*)"$/ do |string| # codeend

Page 77: Behaviour driven infrastructure

When /^I visit "([^"]*)"$/ do |location| visit(location)end

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |input, value| fill_in(input, :with => value)end

Then /^I should see "([^"]*)"$/ do |string| response.body.should match(string)end

Page 78: Behaviour driven infrastructure

blocks of codeare like

unit tests

Page 79: Behaviour driven infrastructure

∴ scenariois a

serial execution of unit tests

Page 80: Behaviour driven infrastructure
Page 81: Behaviour driven infrastructure

Installing

Page 82: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber

Page 83: Behaviour driven infrastructure

Using

Page 84: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber

Page 85: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber$ mkdir -p project/features/steps$ cd project

Page 86: Behaviour driven infrastructure

Testing Workflow

Page 87: Behaviour driven infrastructure

write test

Page 88: Behaviour driven infrastructure

write testrun test

Page 89: Behaviour driven infrastructure

write testrun test

test fails

Page 90: Behaviour driven infrastructure

write testrun test

test fails

make test pass

Page 91: Behaviour driven infrastructure

write testrun test

test fails

make test pass

refactor

Page 92: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber$ mkdir -p project/features/steps$ cd project$ vim features/site.feature

Page 93: Behaviour driven infrastructure

Feature: Google search To increase her knowledge A user Needs a search interface To discover information

Scenario: Home page When I visit "http://google.com.au/" And I fill in "q" with "great balls of fire" Then I should see "great balls of fire"

Page 94: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber$ mkdir -p project/features/steps$ cd project$ vim features/site.feature$ cucumber features/site.feature$ vim features/steps/site_steps.rb

Page 95: Behaviour driven infrastructure

$ apt-get install rubygems $ gem install cucumber$ mkdir -p project/features/steps$ cd project$ vim features/site.feature$ cucumber features/site.feature$ vim features/steps/site_steps.rb$ cucumber features/site.feature

Page 96: Behaviour driven infrastructure
Page 97: Behaviour driven infrastructure

Implications

Page 98: Behaviour driven infrastructure

Continuous Integration

Page 99: Behaviour driven infrastructure

Test server builds

Page 100: Behaviour driven infrastructure

Execute tests

on commit to config management

Page 101: Behaviour driven infrastructure

What environments are the tests run against?

Page 102: Behaviour driven infrastructure

UAT?

Staging?Production?

Page 103: Behaviour driven infrastructure

Destructive tests?

Page 104: Behaviour driven infrastructure

Fixtures

Page 105: Behaviour driven infrastructure

Setup / TeardownPattern

Page 106: Behaviour driven infrastructure

A/B testing

Page 107: Behaviour driven infrastructure
Page 108: Behaviour driven infrastructure

Migration to config management

Page 109: Behaviour driven infrastructure
Page 110: Behaviour driven infrastructure

Continuous Integration&

Monitoring Systems

Page 111: Behaviour driven infrastructure

build

testnotify

deploy

Page 112: Behaviour driven infrastructure

build

testnotify

deploy

Page 113: Behaviour driven infrastructure

testnotify

Page 114: Behaviour driven infrastructure

We’ve been asking the wrong questions

Page 115: Behaviour driven infrastructure

pingconnect

Page 116: Behaviour driven infrastructure

is the host up?is the service available?

Page 117: Behaviour driven infrastructure

is the host up?is the service available?

misconfiguration, bugs triggered by user data, hacked

network stack up

but otherwise broken

Page 118: Behaviour driven infrastructure
Page 119: Behaviour driven infrastructure

Why should I care?

Page 120: Behaviour driven infrastructure

“Nagios checks already do this!”

Page 121: Behaviour driven infrastructure

Cucumber

provides a framework

to phrase questions

Page 122: Behaviour driven infrastructure

Given

Page 123: Behaviour driven infrastructure

When

Page 124: Behaviour driven infrastructure

Then

Page 125: Behaviour driven infrastructure

Lowers the barrier of entry to

writing good checks

Page 126: Behaviour driven infrastructure

Caveat:

You need a firm grasp of language

Page 127: Behaviour driven infrastructure

Feature: Candy Store Wooooooooo!

Scenario: Lollipops When I fly to the moon Then I should see monkeys

Page 128: Behaviour driven infrastructure

Feature: Candy Store Wooooooooo!

Scenario: Lollipops When I fly to the moon Then I should see monkeys

completely valid,

completely useless

Page 129: Behaviour driven infrastructure
Page 130: Behaviour driven infrastructure

Cucumber

provides a common

specification format

dev & ops can share

Page 131: Behaviour driven infrastructure

Cucumber

provides a common

specification format

IT & business can share

Page 132: Behaviour driven infrastructure

Duplication of tests

Page 133: Behaviour driven infrastructure

Development

Page 134: Behaviour driven infrastructure

Production

Page 135: Behaviour driven infrastructure

Cucumber featuresare librarised tests

Cucumber featuresare librarised tests

Page 136: Behaviour driven infrastructure

Same specificationSame specification

Page 137: Behaviour driven infrastructure

Different implementationDifferent implementation

Page 138: Behaviour driven infrastructure
Page 139: Behaviour driven infrastructure

Where to from here?

Page 140: Behaviour driven infrastructure

Write more code.

Page 141: Behaviour driven infrastructure

Patterns.

Page 142: Behaviour driven infrastructure

Expand the library of tests.

Page 143: Behaviour driven infrastructure

Explain to your friends, colleagues, family, pets

these ideas.

Page 144: Behaviour driven infrastructure

Discuss!Thank you.

Page 145: Behaviour driven infrastructure

http://www.flickr.com/photos/51746218@N03/5077975818/http://www.flickr.com/photos/abrinsky/4981594203/http://www.flickr.com/photos/andresrueda/3020304543/http://www.flickr.com/photos/communityfriend/2342578485/http://www.flickr.com/photos/damienroue/2775342201/http://www.flickr.com/photos/elsie/3917813380/http://www.flickr.com/photos/hugo90/5343453489/http://www.flickr.com/photos/iamphejom/4930805430/http://www.flickr.com/photos/jiuck/5060618037/http://www.flickr.com/photos/kusamakura/2435343128/http://www.flickr.com/photos/laurelfan/100700370/http://www.flickr.com/photos/littledebbie11/3208631777/http://www.flickr.com/photos/master-blitzy/1192778834/http://www.flickr.com/photos/nasacommons/4858567480/http://www.flickr.com/photos/nhankamer/4703022414/http://www.flickr.com/photos/normanlowery/4674154988/http://www.flickr.com/photos/paul_lowry/2266388742/http://www.flickr.com/photos/pinprick/467320431/http://www.flickr.com/photos/superciliousness/91346618/http://www.flickr.com/photos/xaviergp/4003730145/

Credits