TDD - Test Driven Development
TDD - Test Driven Development
Agenda
WHY
HOW + Example
Realization 1:
Testing breeds confidence
Confidence
So, if the code works perfectly, and Im never going to change it, then why should I write tests?
Realization 2:
If you write tests before you write your code, you end up writing better code.
It forces me to think before I code Code is more focused and clear I know when Im finished, because all the tests pass
GREEN
REFACTOR
So, if the code works perfectly, and Im never going to change it, and the design is already flawless, then why should I write tests?
Realization 3:
Well written tests are just as good, if not better than documentation.
NOTE: The real example is a better explanation than documents or comments.
Yoga Instructions
1.
2.
3. 4. 5.
Kneel down Put your hands flat in the ground Lift your feet off the ground and balance on your hands Put your knees ahead of your hands Stretch out your back so your body is perpendicular to the ground
Yoga Instructions
Yoga Instructions
The moral
The Goal
White Box
Unit Tests
Acceptance Tests
Endurance Tests
Stress Tests
Example
Need an action which: submits a credit card Specifications:
The user can submit his credit card The server attempts to charge the credit card On failure, display an error message On failure, render a credit card form again On success, store the transaction On success, redirect to the receipt page
TEST_NO_THROW(status = server.chargeCreditCard(MY_CREDIT_CARD) );
ASSERT.EQUAL(STATUS.CHARGED, status);
Inspect + Adapt
Apply Inspect
Adapt
If you havent done it first, you dont know what you are talking about!