test driven development: blueprint, toolbox, and master craft

54
Stephen D. Ritchie – Managing Consultant – Excella Consulting, Inc., 2300 Wilson Blvd, Suite 630, Arlington, VA 22201 – 703.840.8600 – http://excella.com Test Driven Development Stephen Ritchie April 1, 2013 Blueprint, Toolbox, and Master Craft

Upload: stephen-ritchie

Post on 14-Jan-2015

334 views

Category:

Technology


0 download

DESCRIPTION

Many say that the practice of test driven development (TDD) has the ability to transform software engineering. Let’s break it down from a skeptical pragmatist’s viewpoint. This presentation focuses on three key ideas; the blueprint, the toolbox, and the master craft. Let’s look at TDD as a blueprint for writing code and discuss the implications and benefit. Let’s go beyond the theoretical application of TDD and focus on the toolbox, with examples of what developers need to know to get going. Finally, TDD is a master craft of Agile engineering. To be effective with TDD, let’s look at the progression of skills needed to achieve the promised results of TDD and to maximize its value. Stephen is the organizer of DC Alt.Net (http://bit.ly/ZRDxUj). He frequent speaker and trainer on many .NET topics, including automated testing, continuous integration, code analysis, and .NET best practices.Stephen is the author of the book "Pro .NET Best Practices" (http://amzn.to/v8TD8E).

TRANSCRIPT

Page 1: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie – Managing Consultant – Excella Consulting, Inc., 2300 Wilson Blvd, Suite 630, Arlington, VA 22201 – 703.840.8600 – http://excella.com

Test Driven Development

Stephen RitchieApril 1, 2013

Blueprint, Toolbox, and Master Craft

Page 2: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Live Tweet, Slides and Examples

• Twitter: @RuthlessHelp@Apress

• Slides: http://www.slideshare.net/ruthlesshelp

• Code Samples: http://github.com/ruthlesshelp

2

Page 3: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

3

Page 4: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

4

Page 5: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Master Craft

5

Page 6: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Motivation

6

Why test software?

Page 7: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Motivation

7

Page 8: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

Red

Refactor Green

1

2

3

8

Page 9: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

9

0. Think1. Write Test Code2. Write Production Code3. RefactorRepeat 12–40+ cycles/hr

Page 10: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

10

0. Think

Specification (examples)Consumers (API)Users

Page 11: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

11

1. Red

Write a very small amount of test code.

Page 12: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

12

2. Green

Write a very small amount of production code.

Page 13: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

13

3. Refactor

Improve the code.DesignReadabilityTestability

Page 14: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Blueprint

14

Repeat

Cycle12 to 40+ times per hourKeep it simpleRun all the tests, every time

Page 15: Test Driven Development: Blueprint, Toolbox, and Master Craft

Software Works

Make Sure

As You Intended

Automated Tests

Page 16: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

But wait …

16

Page 17: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Temperature Conversion

17

Perhaps an example would

be helpful.

Page 18: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Temperature Conversion

18

Specification By ExampleStart Where You StartDebug As You GoSafely RefactorEngaging (Fun?)

Page 19: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD Katas

• Bowling Score• Roman Numerals• Tennis Score• Conway's Game of Life

• Kata Sites: http://en.wikipedia.org/wiki/Kata_(programming)

19

Page 20: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

But wait …

20

My Manager Wants Me

Slinging Code

Page 21: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Quality, Visibility, Etc.

• Focus on Requirements• Clear, Simple, & Testable• Documents Code’s Behavior• Suite of Regression Tests• Enables & Liberates Change• Visibility (KPI)

– Number of Passing Tests– % Code Coverage

• Problem Prevention

21

Page 22: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

But wait …

22

What’s In It For Me?

Page 23: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Agility

23

http://amzn.to/172CrtT

Page 24: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Agility

• Easier Debugging• Personal Process

– Easy to Get Started– Easy to Keep Going

• Detailed Design Do-Overs• What Was I Thinking?

– What Was That Bozo Thinking?

• Hey, Your API Doesn’t Work

24

Page 25: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

But wait …

25

We Have a Boat-Load of Legacy Code

Page 26: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Legacy Code

26

http://amzn.to/YMpZhl

Page 27: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Legacy Code

• Assembly Coverage• Class Coverage• Method Coverage• Branch Coverage• Boundary Analysis• 100% Code Coverage

27

Page 28: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

28

TDD Books

Page 29: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: Big Picture

29

http://amzn.to/10YXE5a

Page 30: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

TDD: The Art

30

http://amzn.to/XLOt4b

http://bit.ly/XLOZz0Second Edition:

Page 31: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

31

Testing Framework

Run TestsMake Assertions

Page 32: Test Driven Development: Blueprint, Toolbox, and Master Craft

MSTest

- 32 -

Page 33: Test Driven Development: Blueprint, Toolbox, and Master Craft

MBUnit

- 33 -

Page 34: Test Driven Development: Blueprint, Toolbox, and Master Craft

xUnit.net

- 34 -

Page 35: Test Driven Development: Blueprint, Toolbox, and Master Craft

NUnit

- 35 -

http://www.nunit.org/

Page 36: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

36

Mocking Framework

IsolationInteraction Testing

Page 37: Test Driven Development: Blueprint, Toolbox, and Master Craft

Rhino Mocks

- 37 -

Page 38: Test Driven Development: Blueprint, Toolbox, and Master Craft

Moq

- 38 -

http://bit.ly/ZHjQQ0

Page 39: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Unit Testing

39

Perhaps an example would

be helpful.

Page 40: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

The Master Craft

40

Continuous Integration

AutomationMonitoring

Page 41: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

CI Servers

41

Page 42: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

CI in .NET

42

http://amzn.to/10mXYIt

Page 43: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

The Master Craft

43

Code Coverage

Find Missing TestsMonitoring

Page 44: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

44

dotCover

Metrics

http://www.jetbrains.com/dotcover/

Page 45: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

45

Open Cover

Metrics

http://nuget.org/packages/OpenCover

Page 46: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

The Master Craft

http://www.ncover.com/

46

Page 47: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

The Master Craft

47

Inversion of Control

Dependency InjectionIoC ContainersMSDN Article: http://bit.ly/172KUxg

Page 48: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Toolbox

48

Autofac

http://code.google.com/p/autofac/

Page 49: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

The Master Craft

49

Page 50: Test Driven Development: Blueprint, Toolbox, and Master Craft
Page 51: Test Driven Development: Blueprint, Toolbox, and Master Craft

Of Course It’s Safe … After You

Page 52: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Shameless Self Promotion Time!

• “Best Practices” Initiative• Tips and Tricks• Generate Ideas

– Quantifying Value– Biases & Aversions– Tools & Technologies

• Avoid Making the Same Mistakes Once.

52

http://amzn.to/v8TD8E

Page 53: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Shameless Self Promotion Time!

• 40% off eBook at Apress.comhttp://www.apress.com/9781430240235

• Use promo code: FWUG40

• Offer expires 1-May-2013

53

Page 54: Test Driven Development: Blueprint, Toolbox, and Master Craft

Stephen D. Ritchie

Stephen’s Contact Info

• Twitter: @RuthlessHelp

• Email: [email protected]

• Blog: http://ruthlesslyhelpful.net

• LinkedIn: http://www.linkedin.com/in/sritchie

54