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

A Second Look at Unit Testing by Roy Osherove

Embed Size (px)

DESCRIPTION

more info at ArtOfUnitTesting.com . Roy Osherove covers what he learned between the 1st and 2nd edition of his book The Art Of Unit Testing.

Citation preview

Page 1: A Second Look at Unit Testing by Roy Osherove

A Second Look

at Unit Testing@RoyOsherove

[email protected]

Page 2: A Second Look at Unit Testing by Roy Osherove

• 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 by Roy Osherove
Page 4: A Second Look at Unit Testing by Roy Osherove

Bottleneck Ninja Test Review Lion Build Bear

Page 5: A Second Look at Unit Testing by Roy Osherove

Unit

Of

Work

Production Code

Unit Of Work

Return Value/Exceptio

n

Noticeable State Change

3rd Party call

Public API

Test

Page 6: A Second Look at Unit Testing by Roy Osherove

Production Code

Unit Of Work

Return Value/Exceptio

n

Public API

Assert Test

Page 7: A Second Look at Unit Testing by Roy Osherove

Production Code

Unit Of Work

Noticeable State Change

Test

Public API

Ass

ert

Page 8: A Second Look at Unit Testing by Roy Osherove

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 by Roy Osherove

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 by Roy Osherove

Nam

ing b

y U

nit

O

f W

ork

UnitOfWork_Input_Expect

edOutput

UnitOfWork_LogicalAction

_ExpectedChangeInBeha

vior

UnitOfWork_ActionOrInpu

t_ExepectedCallToThirdPa

rty

Page 11: A Second Look at Unit Testing by Roy Osherove

Nam

ing b

y U

nit

O

f W

ork

Addition_PositiveNumbers

_ReturnsSum() Addition_WhenCalled_Res

etsTheNextSum() Addition_NegativeNumber

s_CallsLogger()

Page 12: A Second Look at Unit Testing by Roy Osherove

Setu

p M

eth

ods

Page 13: A Second Look at Unit Testing by Roy Osherove

Isola

tion

Fram

ew

ork

s

Constrained vs. Unconstrained

Page 14: A Second Look at Unit Testing by Roy Osherove
Page 15: A Second Look at Unit Testing by Roy Osherove

Goodbye

R

hin

oM

ock

s Hello FakeItEasy,

NSubstitute

Page 16: A Second Look at Unit Testing by Roy Osherove

Isola

tion

fram

ew

ork

s 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 by Roy Osherove
Page 18: A Second Look at Unit Testing by Roy Osherove

Rspec style is ok

Assert multiple results on

same unit of work

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

LEGACY CODEFaking Deep

System Internals is OKExample - SilverUnit

Page 23: A Second Look at Unit Testing by Roy Osherove

Cross Cutting Fakes

Page 24: A Second Look at Unit Testing by Roy Osherove

Old code

Page 25: A Second Look at Unit Testing by Roy Osherove

Old code FakeNewcode

CROSS CUTTING FAKES

Page 26: A Second Look at Unit Testing by Roy Osherove
Page 27: A Second Look at Unit Testing by Roy Osherove

Impacting

Change

Page 28: A Second Look at Unit Testing by Roy Osherove

6 in

fluence

fo

rces

Personal Ability Motivation Social Ability Motivation Environmental Ability Motivation

Page 29: A Second Look at Unit Testing by Roy Osherove

Anoth

er

book?

Page 30: A Second Look at Unit Testing by Roy Osherove

Tools

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 by Roy Osherove
Page 32: A Second Look at Unit Testing by Roy Osherove

Build and

Delivery

Page 33: A Second Look at Unit Testing by Roy Osherove
Page 34: A Second Look at Unit Testing by Roy Osherove

Build Patterns

Page 35: A Second Look at Unit Testing by Roy Osherove

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 by Roy Osherove

Ext

ract

Scr

ipt

Extract Script

Page 37: A Second Look at Unit Testing by Roy Osherove

Build Chain Triggers

Triggered by checkin

Triggered by end of previous

Manual

Manual

Build Chaining

Page 38: A Second Look at Unit Testing by Roy Osherove

Slow Builds

Do X

Do X + Y

Do X + Y + Z

Do X + y + Z + N

Page 39: A Second Look at Unit Testing by Roy Osherove

Cumulative, Fast Builds

Do X

Do Y

Do Z

Do N

Page 40: A Second Look at Unit Testing by Roy Osherove

How Fast?

Page 41: A Second Look at Unit Testing by Roy Osherove

Extract Script

Shipping Skeleton

Fill in the blanks

Cumulative Builds

Build Waves

Location Agnostic

BeautifulBuilds.com

Page 42: A Second Look at Unit Testing by Roy Osherove

(wtf how many books?)

Page 43: A Second Look at Unit Testing by Roy Osherove

Cours

es

I’m

D

oin

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 by Roy Osherove

A s

hort

song?

Page 45: A Second Look at Unit Testing by Roy Osherove

This is a test line

Page 46: A Second Look at Unit Testing by Roy Osherove

It looks like you’re

doing just fine

Page 47: A Second Look at Unit Testing by Roy Osherove

It’s time for a

song of mine

Page 48: A Second Look at Unit Testing by Roy Osherove

It’s late in the

evening

Page 49: A Second Look at Unit Testing by Roy Osherove

It’s

late

in t

he

eve

nin

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 by Roy Osherove

And then he

asks me

Is the product

alright?

Page 51: A Second Look at Unit Testing by Roy Osherove

And I say

“yes, we deploy it all

tonight”

Page 52: A Second Look at Unit Testing by Roy Osherove

I check in the

changes

Page 53: A Second Look at Unit Testing by Roy Osherove

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 by Roy Osherove

And when they

ask me

Is the code alright?

Page 55: A Second Look at Unit Testing by Roy Osherove

I say

“yes, it seems to

compile tonight’

Page 56: A Second Look at Unit Testing by Roy Osherove

I feel horrible

Because I see

The sadness in

their eyes

Page 57: A Second Look at Unit Testing by Roy Osherove

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 by Roy Osherove

It’s time to go

home now

And 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 by Roy Osherove

When my wife

asks me

“Do you feel

alright?”

Page 60: A Second Look at Unit Testing by Roy Osherove

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

Page 61: A Second Look at Unit Testing by Roy Osherove

I fe

el m

isera

ble Because I’ll guess

The madness in their

talk

Page 62: A Second Look at Unit Testing by Roy Osherove

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 by Roy Osherove

Thank

you!

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

@RoyOsherove Norway & Sweden