Upload
stephen-ritchie
View
333
Download
0
Tags:
Embed Size (px)
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).
Citation preview
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
Stephen D. Ritchie
Live Tweet, Slides and Examples
• Twitter: @RuthlessHelp@Apress
• Slides: http://www.slideshare.net/ruthlesshelp
• Code Samples: http://github.com/ruthlesshelp
2
Stephen D. Ritchie
Blueprint
3
Stephen D. Ritchie
Toolbox
4
Stephen D. Ritchie
Master Craft
5
Stephen D. Ritchie
Motivation
6
Why test software?
Stephen D. Ritchie
Motivation
7
Stephen D. Ritchie
Blueprint
Red
Refactor Green
1
2
3
8
Stephen D. Ritchie
Blueprint
9
0. Think1. Write Test Code2. Write Production Code3. RefactorRepeat 12–40+ cycles/hr
Stephen D. Ritchie
Blueprint
10
0. Think
Specification (examples)Consumers (API)Users
Stephen D. Ritchie
Blueprint
11
1. Red
Write a very small amount of test code.
Stephen D. Ritchie
Blueprint
12
2. Green
Write a very small amount of production code.
Stephen D. Ritchie
Blueprint
13
3. Refactor
Improve the code.DesignReadabilityTestability
Stephen D. Ritchie
Blueprint
14
Repeat
Cycle12 to 40+ times per hourKeep it simpleRun all the tests, every time
Software Works
Make Sure
As You Intended
Automated Tests
Stephen D. Ritchie
But wait …
16
Stephen D. Ritchie
Temperature Conversion
17
Perhaps an example would
be helpful.
Stephen D. Ritchie
Temperature Conversion
18
Specification By ExampleStart Where You StartDebug As You GoSafely RefactorEngaging (Fun?)
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
Stephen D. Ritchie
But wait …
20
My Manager Wants Me
Slinging Code
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
Stephen D. Ritchie
But wait …
22
What’s In It For Me?
Stephen D. Ritchie
TDD: Agility
23
http://amzn.to/172CrtT
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
Stephen D. Ritchie
But wait …
25
We Have a Boat-Load of Legacy Code
Stephen D. Ritchie
TDD: Legacy Code
26
http://amzn.to/YMpZhl
Stephen D. Ritchie
TDD: Legacy Code
• Assembly Coverage• Class Coverage• Method Coverage• Branch Coverage• Boundary Analysis• 100% Code Coverage
27
Stephen D. Ritchie
Toolbox
28
TDD Books
Stephen D. Ritchie
TDD: Big Picture
29
http://amzn.to/10YXE5a
Stephen D. Ritchie
TDD: The Art
30
http://amzn.to/XLOt4b
http://bit.ly/XLOZz0Second Edition:
Stephen D. Ritchie
Toolbox
31
Testing Framework
Run TestsMake Assertions
MSTest
- 32 -
MBUnit
- 33 -
xUnit.net
- 34 -
Stephen D. Ritchie
Toolbox
36
Mocking Framework
IsolationInteraction Testing
Rhino Mocks
- 37 -
Stephen D. Ritchie
Unit Testing
39
Perhaps an example would
be helpful.
Stephen D. Ritchie
The Master Craft
40
Continuous Integration
AutomationMonitoring
Stephen D. Ritchie
CI Servers
41
Stephen D. Ritchie
CI in .NET
42
http://amzn.to/10mXYIt
Stephen D. Ritchie
The Master Craft
43
Code Coverage
Find Missing TestsMonitoring
Stephen D. Ritchie
Toolbox
44
dotCover
Metrics
http://www.jetbrains.com/dotcover/
Stephen D. Ritchie
Toolbox
45
Open Cover
Metrics
http://nuget.org/packages/OpenCover
Stephen D. Ritchie
The Master Craft
http://www.ncover.com/
46
Stephen D. Ritchie
The Master Craft
47
Inversion of Control
Dependency InjectionIoC ContainersMSDN Article: http://bit.ly/172KUxg
Stephen D. Ritchie
Toolbox
48
Autofac
http://code.google.com/p/autofac/
Stephen D. Ritchie
The Master Craft
49
Of Course It’s Safe … After You
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
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
Stephen D. Ritchie
Stephen’s Contact Info
• Twitter: @RuthlessHelp
• Email: [email protected]
• Blog: http://ruthlesslyhelpful.net
• LinkedIn: http://www.linkedin.com/in/sritchie
54