Slide 1

Slide 1 text

Breaking up (with) your test suite poa asd

Slide 2

Slide 2 text

My name is Justin Searls Please tweet me @searls & Say [email protected]

Slide 3

Slide 3 text

Any questions? Tweet @searls during the talk Favorite question gets a book!

Slide 4

Slide 4 text

Any questions? Tweet @searls during the talk Favorite question gets a book!

Slide 5

Slide 5 text

This talk is about z aPPOOIU

Slide 6

Slide 6 text

This talk is about z aPPOOIU relationships

Slide 7

Slide 7 text

I my customers ias al

Slide 8

Slide 8 text

I coding zffrttyu z

Slide 9

Slide 9 text

I testing aske zc

Slide 10

Slide 10 text

We don't test for testing's sake rRth asd

Slide 11

Slide 11 text

I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence. - Kent Beck asdz ty

Slide 12

Slide 12 text

We don't code for code's sake, either mmmmznxdfr lr

Slide 13

Slide 13 text

Writing code is a costly way to solve problems oiz eu

Slide 14

Slide 14 text

Too often, we cheat on our customers with our code c d aoiey

Slide 15

Slide 15 text

How to cheat on your customers: ae ts

Slide 16

Slide 16 text

How to cheat on your customers: ae ts 1. Uncritically assume your favorite way to write code applies to every situation

Slide 17

Slide 17 text

How to cheat on your customers: ae ts 1. Uncritically assume your favorite way to write code applies to every situation 2. There is no #2

Slide 18

Slide 18 text

evh zc Cargo-culting as a service

Slide 19

Slide 19 text

We must challenge our biases in each new context to grow fh ywe

Slide 20

Slide 20 text

iO ZOe infatuation

Slide 21

Slide 21 text

xmt iRosXc Remember TATFT?

Slide 22

Slide 22 text

TDD literally rescued me from the pit of despair.

Slide 23

Slide 23 text

lzxcm zxcmlzcl lzxckz zxczc zxjcozcjoe AOO asodjaosd encz caosdjojo jojo 6 months later ~ ~

Slide 24

Slide 24 text

Why does every refactor break 6 tests?!

Slide 25

Slide 25 text

Why does the build take nine hours to run?!

Slide 26

Slide 26 text

Why are people mocking methods on the object they're testing?!

Slide 27

Slide 27 text

Why can't we get anything done anymore?

Slide 28

Slide 28 text

asodo zoxjcz aoo ueue yyyz cxjk zxcczx and eventually ~ ~

Slide 29

Slide 29 text

the break-up

Slide 30

Slide 30 text

the break-up

Slide 31

Slide 31 text

$ the break-up

Slide 32

Slide 32 text

$ the break-up rm -rf spec features

Slide 33

Slide 33 text

jn poi introspection

Slide 34

Slide 34 text

qwer bvt Why test?

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

!

Slide 37

Slide 37 text

! !

Slide 38

Slide 38 text

! !

Slide 39

Slide 39 text

! ! !

Slide 40

Slide 40 text

! ! !

Slide 41

Slide 41 text

! ! !

Slide 42

Slide 42 text

! ! ! !

Slide 43

Slide 43 text

! ! ! ! !

Slide 44

Slide 44 text

! ! ! ! !

Slide 45

Slide 45 text

! ! ! ! ! !!

Slide 46

Slide 46 text

! ! ! ! ! !! ! ! ! !

Slide 47

Slide 47 text

! ! ! ! ! !! ! ! ! ! Confidence

Slide 48

Slide 48 text

! ! ! ! ! !! ! !!

Slide 49

Slide 49 text

! ! ! ! ! !! Understanding ! !!

Slide 50

Slide 50 text

mni pl Single Responsibility Testing

Slide 51

Slide 51 text

describe "Panda" do end

Slide 52

Slide 52 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } end

Slide 53

Slide 53 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } end

Slide 54

Slide 54 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } ! it "munches bamboo" do end end

Slide 55

Slide 55 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } ! it "munches bamboo" do subject.eat! end end

Slide 56

Slide 56 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } ! it "munches bamboo" do subject.eat! expect(bamboo).to have_received(:munch) end end

Slide 57

Slide 57 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } ! it "munches bamboo" do subject.eat! expect(bamboo).to have_received(:munch) end end

Slide 58

Slide 58 text

asdj zoxc mmr qu psoi rnzc vnkl la later, fixing a bug ~ ~

Slide 59

Slide 59 text

describe "Panda" do let(:bamboo) { double("bamboo").as_null_object } subject { Panda.new(bamboo) } ! it "munches bamboo" do subject.eat! expect(bamboo).to have_received(:munch) end end

Slide 60

Slide 60 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do subject.eat! expect(bamboo).to have_received(:munch) end end

Slide 61

Slide 61 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end end

Slide 62

Slide 62 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do end end

Slide 63

Slide 63 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end

Slide 64

Slide 64 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end

Slide 65

Slide 65 text

asdj zoxc mmr qu psoi rnzc vnkl la one day, I find it ~ ~

Slide 66

Slide 66 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end

Slide 67

Slide 67 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end ? ? ?

Slide 68

Slide 68 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end ? ? ?

Slide 69

Slide 69 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end ? ? ? Why does this test exist?

Slide 70

Slide 70 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end ? ? ? Why does this test exist? What type of test is this?

Slide 71

Slide 71 text

describe "Panda" do let(:bamboo) { Bamboo.find(34) } subject { Panda.new(bamboo) } ! it "munches bamboo" do allow(bamboo).to receive(:munch) subject.eat! expect(bamboo).to have_received(:munch) end ! it "returns bamboo id" do expect(subject.eat!).to eq(34) end end ? ? ? Why does this test exist? How should tests be written? What type of test is this?

Slide 72

Slide 72 text

nini lkre We should know these answers before opening the test!

Slide 73

Slide 73 text

drt byby The purpose, rules, and structure of each test should be immediately clear

Slide 74

Slide 74 text

kpo qw A single test can't address all of our motivations

Slide 75

Slide 75 text

zxc eqr Such tests are unclear:

Slide 76

Slide 76 text

zxc eqr • purpose is hazy Such tests are unclear:

Slide 77

Slide 77 text

zxc eqr • purpose is hazy • rules are debatable Such tests are unclear:

Slide 78

Slide 78 text

zxc eqr • purpose is hazy • rules are debatable • structure is ad hoc Such tests are unclear:

Slide 79

Slide 79 text

tyu fd Unclear tests cost money

Slide 80

Slide 80 text

awe voOa Unclear tests must constantly have their:

Slide 81

Slide 81 text

awe voOa Unclear tests must constantly have their: • purpose rediscovered

Slide 82

Slide 82 text

awe voOa Unclear tests must constantly have their: • purpose rediscovered • rules renegotiated

Slide 83

Slide 83 text

awe voOa Unclear tests must constantly have their: • purpose rediscovered • rules renegotiated • structure reorganized

Slide 84

Slide 84 text

xmcu peo None of those activities have value!

Slide 85

Slide 85 text

ae r Every suite should promote at most type of confidence

Slide 86

Slide 86 text

ae r Every suite should promote at most type of confidence

Slide 87

Slide 87 text

c z Every suite should promote at most type of understanding

Slide 88

Slide 88 text

c z Every suite should promote at most type of understanding

Slide 89

Slide 89 text

suite design zxcm nz

Slide 90

Slide 90 text

oeiz jdk Omakase Rails

Slide 91

Slide 91 text

oeiz jdk Omakase Rails MiniTest

Slide 92

Slide 92 text

oeiz jdk Omakase Rails Views MiniTest

Slide 93

Slide 93 text

oeiz jdk Omakase Rails Views MiniTest MiniTest

Slide 94

Slide 94 text

oeiz jdk Omakase Rails Controllers Views MiniTest MiniTest

Slide 95

Slide 95 text

oeiz jdk Omakase Rails Controllers Views MiniTest MiniTest MiniTest

Slide 96

Slide 96 text

oeiz jdk Omakase Rails Controllers Views Models MiniTest MiniTest MiniTest

Slide 97

Slide 97 text

oeiz jdk Omakase Rails Controllers Views Models MiniTest MiniTest MiniTest

Slide 98

Slide 98 text

ri xc Prime Rails

Slide 99

Slide 99 text

ri xc Prime Rails Cucumber

Slide 100

Slide 100 text

ri xc Prime Rails UI Cucumber

Slide 101

Slide 101 text

ri xc Prime Rails RSpec UI Cucumber

Slide 102

Slide 102 text

ri xc Prime Rails Views RSpec UI Cucumber

Slide 103

Slide 103 text

ri xc Prime Rails Views RSpec RSpec UI Cucumber

Slide 104

Slide 104 text

ri xc Prime Rails Controllers Views RSpec RSpec UI Cucumber

Slide 105

Slide 105 text

ri xc Prime Rails Controllers Views RSpec RSpec RSpec UI Cucumber

Slide 106

Slide 106 text

ri xc Prime Rails Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 107

Slide 107 text

ri xc Prime Rails Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 108

Slide 108 text

zpo qw "Fast Specs" Rails Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 109

Slide 109 text

zpo qw "Fast Specs" Rails Controllers Views Models RSpec RSpec RSpec UI Cucumber RSpec

Slide 110

Slide 110 text

POROs zpo qw "Fast Specs" Rails Controllers Views Models RSpec RSpec RSpec UI Cucumber RSpec

Slide 111

Slide 111 text

What's the problem? rRth asd

Slide 112

Slide 112 text

Redundant test coverage rRth asd

Slide 113

Slide 113 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 114

Slide 114 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 115

Slide 115 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 116

Slide 116 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 117

Slide 117 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 118

Slide 118 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 119

Slide 119 text

ri xc One model change Controllers Views Models RSpec RSpec RSpec UI Cucumber

Slide 120

Slide 120 text

Which leads to: rRth asd

Slide 121

Slide 121 text

ji cnzm Controllers Views Models UI RSpec (›°□°ʣ›ớ ᵲᴸᵲ Rails

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

architecture jd qr

Slide 124

Slide 124 text

+ -

Slide 125

Slide 125 text

+ - app

Slide 126

Slide 126 text

+ - router web app #1 web app #2 walrus data panda data cage control service

Slide 127

Slide 127 text

+ - router walrus data panda data web front- end web back- end web app #1 cage control service

Slide 128

Slide 128 text

+ - walrus data web backend panda data router Feed Zoo Animals Build Feed Plan Provide Meal Fetch Schedule Plan Meal Animal Adapter Compute Portions cage control service Release Food Cage Adapter

Slide 129

Slide 129 text

+ - class ProvidesMeal def initialize... ! def provide(plan) @releases_food.release( @computes_portion.compute(plan) ) end end provides_meal.rb

Slide 130

Slide 130 text

suite design slp er

Slide 131

Slide 131 text

+ - class ProvidesMeal def initialize... ! def provide(plan) @releases_food.release( @computes_portion.compute(plan) ) end end provides_meal.rb

Slide 132

Slide 132 text

+ - walrus data web backend panda data router Feed Zoo Animals Build Feed Plan Provide Meal Fetch Schedule Plan Meal Animal Adapter Compute Portions cage control service Release Food Cage Adapter

Slide 133

Slide 133 text

+ - router walrus data panda data web front- end web back- end web app #1 cage control service

Slide 134

Slide 134 text

+ - router web app #1 web app #2 walrus data panda data cage control service

Slide 135

Slide 135 text

+ - app

Slide 136

Slide 136 text

+ -

Slide 137

Slide 137 text

The greatest test of all: dk rrt

Slide 138

Slide 138 text

Does our software serve its purpose? qwe rtb

Slide 139

Slide 139 text

Wait… what is its purpose? zl dfr

Slide 140

Slide 140 text

Generating revenue? asd er

Slide 141

Slide 141 text

Cutting costs? eit dfp

Slide 142

Slide 142 text

Limiting our liability? xcg ke

Slide 143

Slide 143 text

Funding non-profits? xd asdasdrg

Slide 144

Slide 144 text

Can we write a test for those outcomes? zc er

Slide 145

Slide 145 text

Maybe!* zc er

Slide 146

Slide 146 text

Maybe!* zc er *But not in this talk.

Slide 147

Slide 147 text

+ -

Slide 148

Slide 148 text

+ - app

Slide 149

Slide 149 text

Smoke tests oi fg app

Slide 150

Slide 150 text

Acceptance tests zxc cxoije app

Slide 151

Slide 151 text

Feature tests rv cm app

Slide 152

Slide 152 text

End-to-end tests zoc qwe app

Slide 153

Slide 153 text

Integration tests xu vll app

Slide 154

Slide 154 text

Integration tests xu vll app

Slide 155

Slide 155 text

as cjhf app Smoke Acceptance Feature End-to-end

Slide 156

Slide 156 text

a cv app Smoke Acceptance Feature End-to-end

Slide 157

Slide 157 text

ed cx app S A F E

Slide 158

Slide 158 text

zfh ie app SAFE tests

Slide 159

Slide 159 text

The test's "user"

Slide 160

Slide 160 text

Confidence sought

Slide 161

Slide 161 text

Understanding gained

Slide 162

Slide 162 text

Guidelines

Slide 163

Slide 163 text

Warning Signs

Slide 164

Slide 164 text

app ec ze

Slide 165

Slide 165 text

SAFE

Slide 166

Slide 166 text

A real-world user SAFE

Slide 167

Slide 167 text

web apps app SAFE

Slide 168

Slide 168 text

http services app $ curl http:// SAFE

Slide 169

Slide 169 text

SAFE

Slide 170

Slide 170 text

Application works when it's all glued together SAFE

Slide 171

Slide 171 text

SAFE

Slide 172

Slide 172 text

"How simple is our product?" SAFE

Slide 173

Slide 173 text

Can't fit your tests in 30 minutes? SAFE

Slide 174

Slide 174 text

Can't fit your tests in 30 minutes? SAFE The app is complex

Slide 175

Slide 175 text

SAFE Can't write a test in 30 minutes?

Slide 176

Slide 176 text

SAFE Can't write a test in 30 minutes? The app is complicated

Slide 177

Slide 177 text

SAFE

Slide 178

Slide 178 text

SAFE tests shouldn't know internal APIs SAFE

Slide 179

Slide 179 text

Web tests should bind to user-visible text, not markup SAFE

Slide 180

Slide 180 text

Enforce a fixed-time budget SAFE

Slide 181

Slide 181 text

Time-box the suite 5 minutes 5 minutes SAFE

Slide 182

Slide 182 text

Time-box the suite 5 minutes 5 minutes monthly financials SAFE

Slide 183

Slide 183 text

Time-box the suite 5 minutes 5 minutes monthly financials search SAFE

Slide 184

Slide 184 text

Time-box the suite 5 minutes 5 minutes monthly financials process order search SAFE

Slide 185

Slide 185 text

Time-box the suite 5 minutes 5 minutes monthly financials process order ad words search SAFE

Slide 186

Slide 186 text

Time-box the suite 5 minutes 5 minutes sign-up monthly financials process order ad words search SAFE

Slide 187

Slide 187 text

Time-box the suite 5 minutes 5 minutes sign-up monthly financials process order ad words search daily deals SAFE

Slide 188

Slide 188 text

Time-box the suite 5 minutes 5 minutes sign-up monthly financials process order ad words search daily deals ? SAFE

Slide 189

Slide 189 text

SAFE

Slide 190

Slide 190 text

SAFE Failures due to refactors are false negatives

Slide 191

Slide 191 text

SAFE Beware: human intuition overvalues "realistic" tests

Slide 192

Slide 192 text

SAFE Building multiple releases & branches is expensive

Slide 193

Slide 193 text

SAFE Superlinear Slowdown

Slide 194

Slide 194 text

SAFE Superlinear Slowdown More tests Slower build

Slide 195

Slide 195 text

SAFE Superlinear Slowdown

Slide 196

Slide 196 text

SAFE Superlinear Slowdown Bigger System Slower build

Slide 197

Slide 197 text

! ! ! ! ! !! SAFE

Slide 198

Slide 198 text

! ! ! ! ! !! SAFE

Slide 199

Slide 199 text

! ! ! ! ! !! SAFE

Slide 200

Slide 200 text

+ - app

Slide 201

Slide 201 text

+ - router web app #1 web app #2 walrus data panda data cage control service

Slide 202

Slide 202 text

+ - router walrus data panda data web front- end web back- end web app #1 cage control service

Slide 203

Slide 203 text

Good SAFE tests are accurate ef zc

Slide 204

Slide 204 text

But they're also expensive asd tg

Slide 205

Slide 205 text

And they don't inform our public API's design ef gi

Slide 206

Slide 206 text

Every library or service you write is consumed by somebody tg gz

Slide 207

Slide 207 text

Verify behavior & demonstrate usage with Consumption tests rRth asd

Slide 208

Slide 208 text

Consumption

Slide 209

Slide 209 text

Your 's consumer Consumption

Slide 210

Slide 210 text

Your 's consumer Consumption service

Slide 211

Slide 211 text

Your 's consumer Consumption library

Slide 212

Slide 212 text

Your 's consumer Consumption user interface

Slide 213

Slide 213 text

Your 's consumer Consumption repository

Slide 214

Slide 214 text

Consumption

Slide 215

Slide 215 text

Verifies behavior you're directly responsible for Consumption

Slide 216

Slide 216 text

Consumption

Slide 217

Slide 217 text

Answers: "Is it usable?" Consumption

Slide 218

Slide 218 text

If it's hard to test, then it's hard to use Consumption

Slide 219

Slide 219 text

Consumption

Slide 220

Slide 220 text

Module boundaries should be meaningful beyond testing Consumption

Slide 221

Slide 221 text

Consumption Fakes all external dependencies

Slide 222

Slide 222 text

Consumption Fakes all external dependencies (i.e. can run without access to other services)

Slide 223

Slide 223 text

Consumption Fakes all external dependencies (i.e. can run without access to other services) (e.g. in Travis CI)

Slide 224

Slide 224 text

Exercises public, not private APIs Consumption

Slide 225

Slide 225 text

Organized by consumers' desired outcomes Consumption

Slide 226

Slide 226 text

Consumption

Slide 227

Slide 227 text

Keep consumption tests really fast Consumption

Slide 228

Slide 228 text

faked services Consumption no good reason to be slow

Slide 229

Slide 229 text

The only suite that says you just broke something Consumption

Slide 230

Slide 230 text

! ! ! ! ! !! Consumption

Slide 231

Slide 231 text

! ! ! ! ! !! Consumption

Slide 232

Slide 232 text

! ! ! ! ! !! Consumption

Slide 233

Slide 233 text

+ - router walrus data panda data web front- end web back- end web app #1 cage control service

Slide 234

Slide 234 text

+ - router web app #1 web app #2 walrus data panda data cage control service

Slide 235

Slide 235 text

"If my tests fake out WalrusService how can I trust that GET /walruses still returns walruses?" xc r

Slide 236

Slide 236 text

Why not test across service boundaries? q od

Slide 237

Slide 237 text

Inter-service tests are easy! cd fe

Slide 238

Slide 238 text

Inter-service tests are easy! cd fe 1. Start by not writing them

Slide 239

Slide 239 text

Inter-service tests are easy! cd fe 1. Start by not writing them 2. Continue to not write them

Slide 240

Slide 240 text

Inter-service tests are easy! cd fe 1. Start by not writing them 2. Continue to not write them 3. You're already done. Easy!

Slide 241

Slide 241 text

qwe sd Inter-service tests are tempting, but they're .

Slide 242

Slide 242 text

Inter-service tests are tempting, but they're . hard to set up qwe sd

Slide 243

Slide 243 text

Inter-service tests are tempting, but they're . slow to run qwe sd

Slide 244

Slide 244 text

Inter-service tests are tempting, but they're . redundant coverage qwe sd

Slide 245

Slide 245 text

The root question indicates a lack of trust aie wq

Slide 246

Slide 246 text

Default to trusting your depended-on services zxc see

Slide 247

Slide 247 text

... but sometimes trust isn't appropriate! poae fg

Slide 248

Slide 248 text

Sometimes our usage is abnormal or unsupported xcg asd

Slide 249

Slide 249 text

Sometimes other teams demonstrate blind-spots iocv hgt

Slide 250

Slide 250 text

When trust isn't enough, try writing Contract tests zx rrr

Slide 251

Slide 251 text

Contract

Slide 252

Slide 252 text

The "user" is us! Contract

Slide 253

Slide 253 text

Test is written to represent your interests in somebody else's repo Contract

Slide 254

Slide 254 text

Your needs become part of their Consumption suite Contract

Slide 255

Slide 255 text

If they break your test, they know to call you! Contract

Slide 256

Slide 256 text

Speedier Feedback Contract fast slow

Slide 257

Slide 257 text

Speedier Feedback Contract production release fast slow

Slide 258

Slide 258 text

Speedier Feedback Contract production release git push fast slow

Slide 259

Slide 259 text

Contract

Slide 260

Slide 260 text

Dependencies that we own behave how we need them to Contract

Slide 261

Slide 261 text

Contract

Slide 262

Slide 262 text

We learn: "is this service a good fit for us?" Contract

Slide 263

Slide 263 text

Frequent failures may reveal differing priorities Contract

Slide 264

Slide 264 text

The maintainer learns: "are people using our service as we expect (or desire)?" Contract

Slide 265

Slide 265 text

Maybe this isn't the best service for them Contract

Slide 266

Slide 266 text

Maybe this isn't the best service period. Contract ,

Slide 267

Slide 267 text

Contract

Slide 268

Slide 268 text

Written just like consumption tests Contract

Slide 269

Slide 269 text

Committed into the repo of the depended-on service Contract

Slide 270

Slide 270 text

Maintainers can lower barrier of entry by providing conveniences Contract

Slide 271

Slide 271 text

Contract

Slide 272

Slide 272 text

Not a replacement for human interaction Contract

Slide 273

Slide 273 text

! ! ! ! ! !! Contract

Slide 274

Slide 274 text

! ! ! ! ! !! Contract

Slide 275

Slide 275 text

! ! ! ! ! !! Contract

Slide 276

Slide 276 text

+ - router web app #1 web app #2 walrus data panda data cage control service

Slide 277

Slide 277 text

+ - router walrus data panda data web front- end web back- end web app #1 cage control service

Slide 278

Slide 278 text

+ - walrus data web backend panda data router Feed Zoo Animals Build Feed Plan Provide Meal Fetch Schedule Plan Meal Animal Adapter Compute Portions cage control service Release Food Cage Adapter

Slide 279

Slide 279 text

+ - provides_meal.rb class ProvidesMeal def initialize... ! def provide(plan) @releases_food.release( @computes_portion.compute(plan) ) end end

Slide 280

Slide 280 text

What about TDD? zxc ei

Slide 281

Slide 281 text

"What's the point?" eq rf

Slide 282

Slide 282 text

"We already have lots of tests!" xc fe

Slide 283

Slide 283 text

So far, no feedback about code's design ei kt

Slide 284

Slide 284 text

You already have a definition for "unit" test eq xc

Slide 285

Slide 285 text

I wrote about this a few months ago xi x

Slide 286

Slide 286 text

I wrote about this a few months ago xi x (just Google "tdd failure")

Slide 287

Slide 287 text

No content

Slide 288

Slide 288 text

It even elicited a response from Uncle Bob! qw rf

Slide 289

Slide 289 text

I will refute his arguments and utterly destroy his conclusions. And then, once I'm done salting the ground where he used to live, ...l tell you why I completely agree with him. - Uncle Bob asdz ty

Slide 290

Slide 290 text

I will refute his arguments and utterly destroy his conclusions. And then, once I'm done salting the ground where he used to live, I'll tell you why I completely agree with him. - Uncle Bob asdz ty

Slide 291

Slide 291 text

There's no "one true TDD" iz rgr

Slide 292

Slide 292 text

The principal value of TDD in this model is discovery vj sdf

Slide 293

Slide 293 text

Discovery of tiny, boring, consistent units that break big, scary problems down into small, manageable ones ri gh

Slide 294

Slide 294 text

Discovery

Slide 295

Slide 295 text

The first caller of a new method Discovery

Slide 296

Slide 296 text

Concerned primarily with inputs and output (or side effect) Discovery

Slide 297

Slide 297 text

Also concerned with basic code design details Discovery

Slide 298

Slide 298 text

Inputs & Outcome Discovery Feed Zoo Animals

Slide 299

Slide 299 text

Inputs & Outcome Discovery Feed Zoo Animals (walrus, cheese)

Slide 300

Slide 300 text

Inputs & Outcome Discovery Feed Zoo Animals (walrus, cheese) Walrus has cheese

Slide 301

Slide 301 text

Discovery Now what?!

Slide 302

Slide 302 text

Discovery describe FeedsAnimals do end

Slide 303

Slide 303 text

Discovery describe FeedsAnimals do describe "#feed" do end end

Slide 304

Slide 304 text

Discovery describe FeedsAnimals do describe "#feed" do expect(my_face).to look_like(ಠ_ಠ) end end

Slide 305

Slide 305 text

Discovery Feed Zoo Animals Code by wishful thinking!

Slide 306

Slide 306 text

Discovery Build Feed Plan Provide Meal Feed Zoo Animals Code by wishful thinking!

Slide 307

Slide 307 text

Discovery The test is our sounding board Build Feed Plan Provide Meal Feed Zoo Animals

Slide 308

Slide 308 text

Discovery describe FeedsAnimals do ! ! ! end

Slide 309

Slide 309 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } ! ! end

Slide 310

Slide 310 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! ! end

Slide 311

Slide 311 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! end

Slide 312

Slide 312 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! describe "#feed" do end end

Slide 313

Slide 313 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! describe "#feed" do When(:result) { subject.feed(:walrus, :cheese) } end end

Slide 314

Slide 314 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! describe "#feed" do When(:result) { subject.feed(:walrus, :cheese) } Then { verify(provides_meal).provide(:cheese, :plan) } end end

Slide 315

Slide 315 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! describe "#feed" do Given { give(builds_feed_plan).build(:walrus) {:plan}} When(:result) { subject.feed(:walrus, :cheese) } Then { verify(provides_meal).provide(:cheese, :plan) } end end

Slide 316

Slide 316 text

Discovery describe FeedsAnimals do Given(:builds_feed_plan) { gimme(BuildsFeedPlan) } Given(:provides_meal) { gimme(ProvidesMeal) } ! subject { FeedsAnimals.new(builds_feed_plan, provides_meal) } ! describe "#feed" do Given { give(builds_feed_plan).build(:walrus) {:plan}} When(:result) { subject.feed(:walrus, :cheese) } Then { verify(provides_meal).provide(:cheese, :plan) } end end

Slide 317

Slide 317 text

Discovery Now I have two problems! Build Feed Plan Provide Meal

Slide 318

Slide 318 text

Discovery Now I have two problems! Build Feed Plan Provide Meal

Slide 319

Slide 319 text

Discovery

Slide 320

Slide 320 text

Correct behavior of logical leaf nodes Discovery

Slide 321

Slide 321 text

(a.k.a. pure, first- order functions) Discovery

Slide 322

Slide 322 text

Discovery Feed Zoo Animals Build Feed Plan Provide Meal

Slide 323

Slide 323 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Build Feed Plan Provide Meal

Slide 324

Slide 324 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal

Slide 325

Slide 325 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal

Slide 326

Slide 326 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal ✔️ Compute Portions Release Food Build Feed Plan Provide Meal

Slide 327

Slide 327 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal ✔️ Compute Portions Release Food ✔️ Build Feed Plan Provide Meal

Slide 328

Slide 328 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal ✔️ Compute Portions Release Food ✔️ Build Feed Plan Provide Meal

Slide 329

Slide 329 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal ✔️ Compute Portions Release Food ✔️ Build Feed Plan Provide Meal

Slide 330

Slide 330 text

Discovery

Slide 331

Slide 331 text

Small things Discovery

Slide 332

Slide 332 text

Small things Discovery (Free SRP!)

Slide 333

Slide 333 text

Separation of Roles Discovery

Slide 334

Slide 334 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal

Slide 335

Slide 335 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command

Slide 336

Slide 336 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query

Slide 337

Slide 337 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query Command

Slide 338

Slide 338 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query Query Command

Slide 339

Slide 339 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query Query Logic Command

Slide 340

Slide 340 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query Query Logic Logic Command

Slide 341

Slide 341 text

Discovery Feed Zoo Animals Fetch Schedule Plan Meal Compute Portions Release Food Build Feed Plan Provide Meal Command Query Query Logic Logic Command Command

Slide 342

Slide 342 text

Discovery

Slide 343

Slide 343 text

Command & Query tests discover dependencies with test doubles Discovery

Slide 344

Slide 344 text

Discovery Logic tests discover implementation by usage

Slide 345

Slide 345 text

Discovery (i.e. no test doubles) Logic tests discover implementation by usage

Slide 346

Slide 346 text

Commands and Queries contain very little logic Discovery

Slide 347

Slide 347 text

Pain is good! Discovery

Slide 348

Slide 348 text

Discovery

Slide 349

Slide 349 text

Discovery tests yield small, disposable units Discovery

Slide 350

Slide 350 text

Discovery tests yield small, disposable units Discovery ...so don't be afraid to throw them away!

Slide 351

Slide 351 text

If requirements change, trash a minimal sub-tree of units and drive out a new solution Discovery

Slide 352

Slide 352 text

Re-use is overrated Discovery

Slide 353

Slide 353 text

Extract refactors are a smell Discovery

Slide 354

Slide 354 text

Frameworks will fight you! Discovery

Slide 355

Slide 355 text

Frameworks & TDD try to solve the same problems Discovery

Slide 356

Slide 356 text

Frameworks provide an orderly structure Discovery

Slide 357

Slide 357 text

TDD is an approach for discovering an orderly structure Discovery

Slide 358

Slide 358 text

Discovery testing is at odds with most app frameworks Discovery

Slide 359

Slide 359 text

! ! ! ! ! !! Discovery

Slide 360

Slide 360 text

! ! ! ! ! !! Discovery

Slide 361

Slide 361 text

! ! ! ! ! !! Discovery

Slide 362

Slide 362 text

+ - provides_meal.rb class ProvidesMeal def initialize... ! def provide(plan) @releases_food.release( @computes_portion.compute(plan) ) end end

Slide 363

Slide 363 text

+ - walrus data web backend panda data router Feed Zoo Animals Build Feed Plan Provide Meal Fetch Schedule Plan Meal Animal Adapter Compute Portions cage control service Release Food Cage Adapter

Slide 364

Slide 364 text

"Wow, that's a lot of !" zxc tg mock objects

Slide 365

Slide 365 text

"Wow, that's a lot of !" fake stuff zxc tg

Slide 366

Slide 366 text

"Wow, that's a lot of !" test doubles zxc tg

Slide 367

Slide 367 text

"Aren't those many test doubles a pain?" ad er

Slide 368

Slide 368 text

They can be! asd xc

Slide 369

Slide 369 text

Note: only use doubles when testing collaborators g rg

Slide 370

Slide 370 text

Note: better test double libraries are better gr cz

Slide 371

Slide 371 text

kdasd fk Discovery tests try to improve dependencies' APIs

Slide 372

Slide 372 text

kg er But we can't change 3rd party APIs

Slide 373

Slide 373 text

er zxc Mocking what you don't own leads to useless pain

Slide 374

Slide 374 text

Wrap 3rd party API calls in adapters that you do own uc vt

Slide 375

Slide 375 text

Wrap 3rd party API calls in adapters that you do own uc vt (And mock those adapters instead)

Slide 376

Slide 376 text

Typically, adapters shouldn't need tests zx bt

Slide 377

Slide 377 text

Most tests exercise features that make use 3rd party APIs jd hn

Slide 378

Slide 378 text

It sometimes make sense to test code we don't own separately jd hn

Slide 379

Slide 379 text

When you want to respond to 3rd party failures differently, write Adapter tests jd hn

Slide 380

Slide 380 text

Adapter

Slide 381

Slide 381 text

Your application, pondering its relationship with a 3rd party API Adapter

Slide 382

Slide 382 text

Exercises your adapter API under realistic-enough circumstances Adapter

Slide 383

Slide 383 text

Adapter

Slide 384

Slide 384 text

Adapter Tests of libraries warn of unsafe upgrades

Slide 385

Slide 385 text

Adapter Tests of network services warn of outages & breaking changes

Slide 386

Slide 386 text

Adapter

Slide 387

Slide 387 text

Adapters (& tests) specify how you depend on a thing Adapter

Slide 388

Slide 388 text

Establishes boundaries, prevents 3rd party API references from seeping throughout your app Adapter

Slide 389

Slide 389 text

Drastically reduces the cost of replacing dependencies later Adapter

Slide 390

Slide 390 text

Adapter

Slide 391

Slide 391 text

Only test adapters with good cause Adapter

Slide 392

Slide 392 text

"Don't test the framework." Adapter

Slide 393

Slide 393 text

Adapter

Slide 394

Slide 394 text

Adapter test suites of network code can be tricky to run in CI Adapter

Slide 395

Slide 395 text

It's easier to test 3rd party services from your SAFE suite Adapter

Slide 396

Slide 396 text

All adapter tests are likely to be slow in ways outside your control Adapter

Slide 397

Slide 397 text

! ! ! ! ! !! Adapter

Slide 398

Slide 398 text

! ! ! ! ! !! Adapter

Slide 399

Slide 399 text

! ! ! ! ! !! Adapter

Slide 400

Slide 400 text

And that's just way to break up your test suite asd

Slide 401

Slide 401 text

And that's just way to break up your test suite asd

Slide 402

Slide 402 text

My name is Justin Searls Please tweet me @searls & Say [email protected]

Slide 403

Slide 403 text

Like everyone, we're hiring! Just [email protected]

Slide 404

Slide 404 text

Please say hello if your team could use our team's help #

Slide 405

Slide 405 text

Quotation Marks designed by Horacio Bella from the thenounproject.com ! Happy designed by Michael Hourigan from the thenounproject.com ! Tired designed by Aha-Soft from the thenounproject.com ! Indifference designed by Paul F. from the thenounproject.com ! Mad designed by Aha-Soft from the thenounproject.com ! Sad designed by Simple Icons from the thenounproject.com ! Marker designed by Jeff Seevers from the thenounproject.com ! Database designed by Grant Fisher from the thenounproject.com ! Cloud designed by Thomas Hirter from the thenounproject.com ! Safety Net designed by irene hoffman from the thenounproject.com ! Light Bulb designed by Olivier Guin from the thenounproject.com ! Scale designed by Stephanie Wauters from the thenounproject.com ! Warning designed by Lorena Salagre from the thenounproject.com ! Reload designed by Mateo Zlatar from the thenounproject.com Noun project attribution