63
A Second Look at Unit Testing @RoyOsherove [email protected]

A Second Look at Unit Testing

  • Upload
    lynda

  • View
    43

  • Download
    2

Embed Size (px)

DESCRIPTION

A Second Look at Unit Testing. @ RoyOsherove [email protected]. Unit Of Work Setup Methods Constrained vs. Unconstrained Isolation Frameworks Principles of Good Isolation Frameworks Faking Deep Legacy is OK Six Influence Forces Beautiful Builds. Test Review Lion. Bottleneck Ninja. - PowerPoint PPT Presentation

Citation preview

Page 1: A  Second Look  at  Unit Testing

A Second Look

at Unit Testing@RoyOsherove

[email protected]

Page 2: A  Second Look  at  Unit Testing

• Unit Of Work• Setup Methods

• Constrained vs. Unconstrained Isolation

Frameworks• Principles of Good Isolation Frameworks

• Faking Deep Legacy is OK• Six Influence Forces

• Beautiful Builds

Page 3: A  Second Look  at  Unit Testing
Page 4: A  Second Look  at  Unit Testing

Bottleneck Ninja Test Review Lion Build Bear

Page 5: A  Second Look  at  Unit Testing

Unit

Of W

orkProduction

Code

Unit Of Work

Return Value/Exceptio

nNoticeable

State Change 3rd Party call

Public API

Test

Page 6: A  Second Look  at  Unit Testing

Production Code

Unit Of Work

Return Value/Exceptio

n

Public API

Assert Test

Page 7: A  Second Look  at  Unit Testing

Production Code

Unit Of Work

Noticeable State Change

Test

Public API

Asse

rt

Page 8: A  Second Look  at  Unit Testing

Production Code

Unit Of Work

3rd Party call

Test

Public API As

sert

3rd Party

Unit Of Work

Page 9: A  Second Look  at  Unit Testing

Production Code

Unit Of Work

3rd Party call

Test

Public API As

sert

3rd Party

Unit Of Work

Mock

Page 10: A  Second Look  at  Unit Testing

Nam

ing

by U

nit

Of W

ork

UnitOfWork_Input_ExpectedOutput

UnitOfWork_LogicalAction_ExpectedChangeInBehavior

UnitOfWork_ActionOrInput_ExepectedCallToThirdParty

Page 11: A  Second Look  at  Unit Testing

Nam

ing

by U

nit

Of W

ork

Addition_PositiveNumbers_ReturnsSum()

Addition_WhenCalled_ResetsTheNextSum() Addition_NegativeNumber

s_CallsLogger()

Page 12: A  Second Look  at  Unit Testing

Setu

p Me

thod

s

Page 13: A  Second Look  at  Unit Testing

Isola

tion

Fram

ewor

ks Constrained vs. Unconstrained

Page 14: A  Second Look  at  Unit Testing
Page 15: A  Second Look  at  Unit Testing

Good

bye

Rhin

oMoc

ks Hello FakeItEasy,

NSubstitute

Page 16: A  Second Look  at  Unit Testing

Isola

tion

fram

ewor

ks Fu

ture

s

Usability Readability Good Errors Simplicity Robust future proof tests Less over specification

Non strict Recursive Fakes

Page 17: A  Second Look  at  Unit Testing
Page 18: A  Second Look  at  Unit Testing

Rspec style is ok

Assert multiple results on

same unit of work

Page 19: A  Second Look  at  Unit Testing
Page 20: A  Second Look  at  Unit Testing
Page 21: A  Second Look  at  Unit Testing
Page 22: A  Second Look  at  Unit Testing

LEGACY CODEFaking Deep

System Internals is OKExample - SilverUnit

Page 23: A  Second Look  at  Unit Testing

Cross Cutting Fakes

Page 24: A  Second Look  at  Unit Testing

Old code

Page 25: A  Second Look  at  Unit Testing

Old code FakeNewcode

CROSS CUTTING FAKES

Page 26: A  Second Look  at  Unit Testing
Page 27: A  Second Look  at  Unit Testing

Impacting Change

Page 28: A  Second Look  at  Unit Testing

6 in

fluen

ce

forc

es

Personal Ability Motivation Social Ability Motivation Environmental Ability Motivation

Page 29: A  Second Look  at  Unit Testing

Anot

her b

ook?

Page 30: A  Second Look  at  Unit Testing

Tool

s

Pex – yes Moles (ms fakes) – NO JustMock - Maybe Nuget – YES Chocolatey – YES

TeamCity – YES FinalBuilder – YES Ruby and Rake – Maybe Amazon AWS agent hosting –

YES Git for very small commits -

YES

Page 31: A  Second Look  at  Unit Testing
Page 32: A  Second Look  at  Unit Testing

Build and Delivery

Page 33: A  Second Look  at  Unit Testing
Page 34: A  Second Look  at  Unit Testing

Build Patterns

Page 35: A  Second Look  at  Unit Testing

Build

Scr

ipt

Inje

ctio

n Allow version aware builds Build scripts are part

of source control Build configurations on

the CI server are dumb triggers

Page 36: A  Second Look  at  Unit Testing

Extra

ct S

crip

t

Extract Script

Page 37: A  Second Look  at  Unit Testing

Build Chain Triggers

Triggered by checkin

Triggered by end of previous

Manual

Manual

Build Chaining

Page 38: A  Second Look  at  Unit Testing

Slow Builds

Do X

Do X + Y

Do X + Y + Z

Do X + y + Z + N

Page 39: A  Second Look  at  Unit Testing

Cumulative, Fast Builds

Do X

Do Y

Do Z

Do N

Page 40: A  Second Look  at  Unit Testing

How Fast?

Page 41: A  Second Look  at  Unit Testing

Extract Script Shipping Skeleton Fill in the blanks Cumulative Builds Build Waves Location Agnostic

BeautifulBuilds.com

Page 42: A  Second Look  at  Unit Testing

(wtf how many books?)

Page 43: A  Second Look  at  Unit Testing

Cour

ses I

’m

Doin

g

Beautiful builds TDD with JS TDD with Ruby Art of Unit Testing in .NET from scratch [email protected]

Norway & Sweden Osherove.com for info

Page 44: A  Second Look  at  Unit Testing

A sh

ort s

ong?

Page 45: A  Second Look  at  Unit Testing

This is a test line

Page 46: A  Second Look  at  Unit Testing

It looks like you’re

doing just fine

Page 47: A  Second Look  at  Unit Testing

It’s time for a

song of mine

Page 48: A  Second Look  at  Unit Testing

It’s late in the evening

Page 49: A  Second Look  at  Unit Testing

It’s l

ate

in th

e ev

enin

g

I’m wondering what words to say It’s so hard to breath

here The customer’s face is gray

Page 50: A  Second Look  at  Unit Testing

And then he asks me

Is the product

alright?

Page 51: A  Second Look  at  Unit Testing

And I say

“yes, we deploy it all tonight”

Page 52: A  Second Look  at  Unit Testing

I check in the changes

Page 53: A  Second Look  at  Unit Testing

I check in the changes

The code doesn’t even

compile

I wish I was home now

Instead I fake a big smile

Page 54: A  Second Look  at  Unit Testing

And when they ask me

Is the code alright?

Page 55: A  Second Look  at  Unit Testing

I say

“yes, it seems to

compile tonight’

Page 56: A  Second Look  at  Unit Testing

I feel horribleBecause I see

The sadness in

their eyes

Page 57: A  Second Look  at  Unit Testing

When they find out

That the product

Doesn’t even have

log files

This thing is

doomed

Page 58: A  Second Look  at  Unit Testing

It’s time to go

home nowAnd I’ve got an aching

head

So I lock my computer

And pray that tomorrow

I’m dead

Page 59: A  Second Look  at  Unit Testing

When my wife asks me

“Do you feel

alright?”

Page 60: A  Second Look  at  Unit Testing

I say “yes. Let’s watch game of thrones tonight”

Page 61: A  Second Look  at  Unit Testing

I fee

l mise

rabl

e Because I’ll guess The madness in their

talk

Page 62: A  Second Look  at  Unit Testing

When they find out that tomorrow I don’t plan to come to work And write my CV

Page 63: A  Second Look  at  Unit Testing

Than

k yo

u!

Beautiful builds TDD with JS TDD with Ruby Art of Unit Testing in .NET from scratch [email protected]

@RoyOsherove Norway & Sweden