Amir Barylko - TDD MavenThought Inc. AMIR BARYLKO WHY TDD? WPG RUBY UG 2011
Oct 31, 2014
Amir Barylko - TDD MavenThought Inc.
AMIR BARYLKO
WHY TDD?
WPG RUBY UG 2011
Amir Barylko - TDD MavenThought Inc.
INTROWhy projects fail?
Reality CheckNo more excuses
Why TDD?
Amir Barylko - TDD MavenThought Inc.
WHY PROJECTS FAIL?
•Delivering late or over budget
•Delivering the wrong thing
•Unstable in production
•Costly to maintain
Amir Barylko - TDD MavenThought Inc.
REALITY CHECK
•It is impossible to gather all the requirements at the beginning of a project.
•Whatever requirements you do gather are guaranteed to change.
•There will always be more to do than time and money will allow.
Amir Barylko - TDD Workshop PRDC 2011 MavenThought Inc.
NO MORE EXCUSES
• It works on my computer!
• It was like that when I got here!
• The previous developer didn’t know XXXX!
• We need a satellite connection in order to run it!
• We can’t reproduce the error!
• We can’t test that!
Amir Barylko - TDD Workshop PRDC 2011 MavenThought Inc.
WHY TDD?
•Prove that your code works
•Avoid waste (debugging)
• Increment code quality
•Better design
•Regression tests as byproduct
•Make changes with confidence
•Bring back the joy of coding!
Amir Barylko - TDD MavenThought Inc.
APPLYING TDDIteration 0 .. N
Quality as a Driver Red - Green - Refactor
Amir Barylko - TDD MavenThought Inc.
ITERATION 0
• Flush out architecture.
• Setup Testing harness for TDD and BDD.
• Setup continuous integration.
• Setup scripts to build, deploy, etc.
• Setup visual communication tools.
Amir Barylko - TDD MavenThought Inc.
ITERATION 1.. N
• Start by Story Planning
• Pair programming (switching often)
• Daily Scrum
• End with Retrospective
Every day!
Amir Barylko - TDD MavenThought Inc.
QUALITY AS A DRIVERRed
GreenRefactor
BDD
TDD
Red
GreenRefactor
Amir Barylko - TDD MavenThought Inc.
RED
•Write a test that fails
•Relax, is ok if it compiles
Amir Barylko - TDD MavenThought Inc.
GREEN
•Try to make the test pass
•Do a simple solution
•Use default values (not throwing exceptions)
•Don’t worry if the code “smells”
Amir Barylko - TDD MavenThought Inc.
REFACTOR
•Avoid repeating code
•Avoid hardcoding dependencies
•Avoid “write only” code
•Refactor with confidence!
•Run all tests if possible
Amir Barylko - TDD MavenThought Inc.
DEMOMediaLibrary
AddTop10
Amir Barylko - TDD MavenThought Inc.
SUMMARYLimits
BenefitsChallengesAdoption
Amir Barylko - TDD MavenThought Inc.
LIMITS OF TDD
• Unit test
• Integration test
• Acceptance test
Amir Barylko - TDD MavenThought Inc.
BENEFITS
•Let the methodology drive
•It will save your bacon!
•High quality the whole way!
•Very few bugs!
•Do your duty as developer!
Amir Barylko - TDD MavenThought Inc.
CHALLENGES
• Very different from conventional testing
• Many developers find it complex to learn at first
• Hard to start without a Mentor
• Management buy in
• Difficult to keep under deadline pressure
• Beware of code coverage!
Amir Barylko - TDD MavenThought Inc.
ADOPTION
• Find Mentor/Couch/Trainer
• Small iterations
• Have metrics ready (velocity, etc)
• Do whatever works for you
• Find out which tools will benefit you
• Automate, automate, automate!
Amir Barylko - TDD MavenThought Inc.
QUESTIONS?