Upload
joel-cochran
View
125
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Test Driven Development is a technique that requires Unit Tests for code to be written before the code itself. By placing the emphasis on testing, developers can define success before code is written. This helps us answer that elusive question of "when is code done?" TDD offers additional benefits such as only writing code you need to satisfy your requirements (YAGNI), and enhanced maintainability.
Citation preview
Consulting/Training
Joel Cochran
Lead Developer, WintellectNOW.com
@joelcochran
Intro to Test Driven Development (TDD)
Consulting/Training
About Me
Microsoft Client Development MVPASPInsiderTwitter: @joelcochranEmail: [email protected]: joelcochran.comLead Developer, WintellectNOW
Consulting/Training
About Wintellect
Founded by top experts on Microsoft – Jeffrey Richter, Jeff Prosise, and John Robbins – we pull out all the stops to help our customers achieve their goals through advanced software-based consulting and training solutions.
consulting
Wintellect helps you build better software, faster, tackling the tough projects and solving the software and technology questions that help you transform your business.
Architecture, Analysis and Design Full lifecycle software development Debugging and Performance tuning Database design and development
training
Wintellect's courses are written and taught by some of the biggest and most respected names in the Microsoft programming industry.
Learn from the best. Access the same training Microsoft’s developers enjoy
Real world knowledge and solutions on both current and cutting edge technologies
Flexibility in training options – onsite, virtual, on demand
who we are
Consulting/TrainingIndividuals | Businesses | Enterprise Organizations
Authors Enjoy:
Royalty Income
Personal Branding
Cross-Sell Opps
Free library access
Subscribers Enjoy:
Expert Instructors
Quality Content
Practical Application
All Devices
Try it freeCode: <INSERT CODE
HERE>WintellectNOW.co
m
Wintellect’s On-Demand Video Training Solution
COCHRAN-13
Consulting/Training
Interview with a Method
Consulting/Training
The Multiply Method Signature
Int32 Multiply(Int32[] values)
Consulting/Training
Question #1
What parameter(s) do you take?
An Array of Int32
Consulting/Training
Question #2
What value type do you return?
Int32
Consulting/Training
Question #3
What happens when I pass you:[3, 4]?
I don’t know
Consulting/Training
Question #4
What happens when I pass you:[7]?
I don’t know
Consulting/Training
Question #5
What happens when I pass you:[-5, 12, 10, -3]?
I don’t know
Consulting/Training
Question #6
What happens when I pass you:null?
I don’t know
Consulting/Training
Question #7
What happens when I pass you:[23, Int32.MaxValue]?
I don’t know
Consulting/Training
Question #8
You don’t seem to know much…
If you don’t know the answer to these questions, who does?
The Unit Tests
Consulting/Training
What is a Unit Test?
Code that tests code
Small discrete chunks (units)
One test, one condition
Based on assumptions
Should be automated and repeatable
Consulting/Training
What a Unit Test is Not
An end-to-end test
Connected to live data
Performing external functions (like sending an Email)
User tests
Consulting/Training
Why write Unit Tests?
Test code to ensure proper functionality given certain assumptions
Exercise code without running the app
Write once, run a million times
Guards against unintended consequences
Tests define success
Consulting/Training
What is TDD?
Unit Tests are written before the code
Helps shape the code to the task at hand
Provides focus (YAGNI)
The test defines success
Run all tests every time
Consulting/Training
TDD Pattern
REDwrite a failing test
GREEN write enough code to
pass
REFACTORengineer the code
Consulting/Training
Anatomy of a Unit Test
Arrange
•Assumptions•Expectations
Act•Execute•Results
Assert•Compare•Report
Consulting/Training
TDD Kata
Daily exercise – 30 minutes or less
Roy Osherove, author of “The Art of Unit Testing”, Manning Publications
http://osherove.com/tdd-kata-1/
Let’s code!
Consulting/Training
The String Calculator Kata
Consulting/Training
StringCalculator Kata