Post on 21-Dec-2014
description
Introduction to Test Driven Development
Sivasubramaniam Arunachalam
Mar 29, 2014
@sivaa_in
http://barcampbangalore.org/bcb/bcb15/introduction-to-test-driven-development-tdd
It’s me!
It’s about you!
#barcampblr
#tdd
Just Before We Get
Started
How many of you are
• Developers
• Testers/Quality
• Manual
• Automated
Manual/Automated Developers?
> 100K
> 5
Waste of time
No
Opportunity
Test Driven Development
TDD is NOT a Testing Strategy
TDD is a Design Strategy
TDD is NOT for Testers
TDD is for Developers
(1) – (2) – (3)
(1) – (2) – (3)
Others
Code
(1) – (2) – (3)
Legacy
Systems
(1) – (2) – (3)
Change in
Architecture
How to Start?
How I have Started?
The Correct way
Refactoring? • Removing duplication
• Make the logic simpler
• Make the code easier to read
TDD Components
• Unit Tests
• Functional Tests
• Integration Tests
Unit Tests
Unit Tests Best Practices
• Focus one Class/Method
• Keep it under 10 seconds
• Execute 100 tests/second
• Runs only on memory
Integration Tests
Functional Tests
Are you ready now?
Everyone likes to have tests
but
Few people like writing them.
Only way to test Interfaces & Design
Immediate
Confirmation
Helps to re-think what
Needs to be Coded
Acts as a
Low Level Spec
Less Rework
Regression due to refactoring
This is the only way to find it
No More
Dead Code
Less code = Less bugs
Unit Tests might act as a
Documentation
Less
Debugging
Lets calculate the Cost
2 x $25 = $50
N x $M = $5K will become
Faster
Development
By Products
• Forces you to write small classes (focused on one thing.)
• Helps create loosely coupled code
• Measure implementation progress
How Much is enough?
Can I test Getters and Setters?
Can I test Third-Party Libraries?
(How)
Can I test Private Methods?
(How)
Can I test User Interfaces?
Be a Cool dude and exclude
Where to focus
More and Less?
Mock Objects
Scaling
When do we
FAIL?
Why businesses don’t like TDD?
How to start TDD for
existing applications?
Potential
Challenges
Applicable for
Startups?
Is it really
worth it?
http://www.ipd.uni-karlsruhe.de/Tichy/uploads/publikationen/35/edser03.pdf
http://programmers.stackexchange.com/questions/206355/the-relative-cost-efficiency-of-acceptance-test-driven-development
Someone is using it?
http://agilepainrelief.com/notesfromatooluser/2008/11/misconceptions-with-test-driven-development.html
Lets see some (test) code
Dis-advantages (You will lose)
• Ability to say you are "done" before testing all your code.
• Opportunity to learn through debugging.
• Flexibility to ship code that you aren't sure of.
• Freedom to tightly couple your modules.
• Option to skip writing low level design documentation.
• Stability that comes with code that everyone is afraid to change.
• Capability to write hundreds or thousands of lines of code before running it.
TFD vs TDD
Code without tests is
broken by design.
- Jacob Kaplan-Moss
Debugging is twice as hard as writing the code in the first place.
- Brian Kernighan
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
- Brian Kernighan
Thank You! siva@sivaa.in
bit.ly/sivasubramaniam bit.ly/sivaa_in
References https://www.youtube.com/watch?v=DodJQyHsmHI