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.
Intro to Test Driven Development (TDD) and the String Calculator Kata
1. Intro to Test Driven Development (TDD)
Consulting/Training
2. Consulting/Training
About Me
Microsoft Client Development MVP
ASPInsider
Twitter: @joelcochran
Email: joelcochran@gmail.com
Blog: joelcochran.com
Lead Developer, WintellectNOW
3. 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
4. Wintellect’s On-Demand Video Training Solution
Try it free
Code: <INSERT CODE HERE> WintellectNOW.com
COCHRAN-13
Authors Enjoy:
Royalty Income
Personal Branding
Cross-Sell Opps
Free library access
Subscribers Enjoy:
Expert Instructors
Quality Content
Practical Application
All Devices
Consulting/Training Individuals | Businesses | Enterprise Organizations
14. 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
15. 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
16. What a Unit Test is Not
Consulting/Training
An end-to-end test
Connected to live data
Performing external functions (like sending an Email)
User tests
17. 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
18. 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
20. Anatomy of a Unit Test
Consulting/Training
Arrange
• Assumptions
• Expectations
Act
• Execute
• Results
Assert
• Compare
• Report
21. 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!
Actual result == Int32.MaxValue – (multiplier – 1) == 2147483625
Int32.MaxValue = 2147483647
Every time you multiply (except for * 1) you overflow the Integer value
Subtract 1 for the value of 0 every time this happens