© 2013 iZenBridge | CONFIDENTIAL
Introduction
to
Test Driven
Development
(TDD)
© 2013 iZenBridge | CONFIDENTIAL
Introductions!
1.Your Name
2.Current company & Role
3.Experience with Agile and TDD
© 2013 iZenBridge | CONFIDENTIAL
Agile Software Development
© 2013 iZenBridge | CONFIDENTIAL
Traditional Design – Code – Test
Design Code Test
Test Code
Design /
Refactor
© 2013 iZenBridge | CONFIDENTIAL
Why Not Testing at the End?
• Hard to improve quality of
existing code –
Complacency and Recency
• Feedback opportunity is
lost
• The future state of the
project is difficult to gauge
• Testing is more likely to be
cut
© 2013 iZenBridge | CONFIDENTIAL
Stress and Testing
Project
Stress
Less
Testing
Just get it done, will ya?
© 2013 iZenBridge | CONFIDENTIAL
Test Automation Pyramid
UI
Service
Unit
UI
Service
Unit
AgileTraditional
© 2013 iZenBridge | CONFIDENTIAL
Test First Development
ATDD and TDD
© 2013 iZenBridge | CONFIDENTIAL
ATDD vs TDD
Source: Test Driven: Practical TDD and Acceptance TDD for Java Developers
© 2013 iZenBridge | CONFIDENTIAL
Why TDD?
The Benefits of TDD:
• Limits WIP – a key Lean principle
• Ensures testing at lower granularity level – the smallest
testable unit of code
• Ensures no untested code goes to production
• Helps high degree of conformity between code and the
real business requirements
• Helps keep unused code out of the system (unwritten)
• Makes codebase more maintainable – via regression
testing
© 2013 iZenBridge | CONFIDENTIAL
The TDD Cycle
 Red
 Green
 Clean
Test
Code
Refactor
© 2013 iZenBridge | CONFIDENTIAL
Three Laws/ Rules of TDD
You will not write any production
code until you have written a failing
unit test.
First Law
© 2013 iZenBridge | CONFIDENTIAL
Three laws of TDD
You will not write more of a unit
test than is sufficient to fail, and
not compiling is failing
Second Law
© 2013 iZenBridge | CONFIDENTIAL
Three laws of TDD
You will not write more production
code that is sufficient to pass the
currently failing test.
Third Law
© 2013 iZenBridge | CONFIDENTIAL
Misconceptions About TDD
• Writing code first, then tests is
same as TDD
• TDD isn’t useful for designing
architecture
• Takes too much time
• Too complex to learn and
implement
• TDD is only good for small
projects
© 2013 iZenBridge | CONFIDENTIAL
© 2013 iZenBridge | CONFIDENTIAL
Let’s Build Something Now!
© 2013 iZenBridge | CONFIDENTIAL
String Calculator – TDD Exercise
Define Scope:
• Supported operators?
• Acceptable characters?
• Whitespace?
• Max length of expression – number of operations?
• Max length of each number?
• Fractions?
• Parenthesis?
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
Time to start Failing!
• Reminders:
• Test, Code, Refactor – REPEAT until Done!
• Add feature layers one by one, in small manageable
increments
• Setup
• Eclipse for Java Development
• JDK
• Team formation
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
1. Two literal addition
A + B
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
2. Multiple literal addition
A + B + C
A + B + C + D
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
3. Combination of addition and
subtraction
A + B – C
or
A – B + C
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
4. Simple multiplication
A * B
A * B * C
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
5. Simple division
A / B
A / B / C
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
6. Combination of multiplication
and division
A * B / C
A / B * C
Does order matter?
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
7. Combination of all four
A + B – C * D / E
Order does matter here!
© 2013 iZenBridge | CONFIDENTIAL
String Calculator (continued)
8. Invalid expressions
• Banned chars - alpha, parenthesis, special chars
• Space between a number
• Two operators clubbed together
• First number negative
• Invalid decimal number
© 2013 iZenBridge | CONFIDENTIAL
What Next?
Certified Scrum Developer (CSD)
A 3-day course certified by Scrum Alliance that focuses on
specialized Agile engineering skills:
 Test Driven Development (TDD)
 ATDD, BDD – Selenium/ Cucumber
 Continuous Integration – Jenkins
 Agile Design and Architecture
 Refactoring
 Collaboration
© 2013 iZenBridge | CONFIDENTIAL
References
 Test Driven Development: By Example - Kent Beck
 Succeeding with Agile - Mike Cohn
 Test Driven: Practical TDD and Acceptance TDD for Java
Developers - Lasse Koskela
© 2013 iZenBridge | CONFIDENTIAL
Stay Connected
YouTube
www.youtube.com/izenbridge
LinkedIn Group
PMI-ACP: Agile Certification Made Easy
Saket.Bansal@iZenBridge.com
SunjayKumar@gmail.com
www.iZenBridge.com
forum.iZenBridge.com

Workshop on Test Driven Development (TDD) Noida

  • 1.
    © 2013 iZenBridge| CONFIDENTIAL Introduction to Test Driven Development (TDD)
  • 2.
    © 2013 iZenBridge| CONFIDENTIAL Introductions! 1.Your Name 2.Current company & Role 3.Experience with Agile and TDD
  • 3.
    © 2013 iZenBridge| CONFIDENTIAL Agile Software Development
  • 4.
    © 2013 iZenBridge| CONFIDENTIAL Traditional Design – Code – Test Design Code Test Test Code Design / Refactor
  • 5.
    © 2013 iZenBridge| CONFIDENTIAL Why Not Testing at the End? • Hard to improve quality of existing code – Complacency and Recency • Feedback opportunity is lost • The future state of the project is difficult to gauge • Testing is more likely to be cut
  • 6.
    © 2013 iZenBridge| CONFIDENTIAL Stress and Testing Project Stress Less Testing Just get it done, will ya?
  • 7.
    © 2013 iZenBridge| CONFIDENTIAL Test Automation Pyramid UI Service Unit UI Service Unit AgileTraditional
  • 8.
    © 2013 iZenBridge| CONFIDENTIAL Test First Development ATDD and TDD
  • 9.
    © 2013 iZenBridge| CONFIDENTIAL ATDD vs TDD Source: Test Driven: Practical TDD and Acceptance TDD for Java Developers
  • 10.
    © 2013 iZenBridge| CONFIDENTIAL Why TDD? The Benefits of TDD: • Limits WIP – a key Lean principle • Ensures testing at lower granularity level – the smallest testable unit of code • Ensures no untested code goes to production • Helps high degree of conformity between code and the real business requirements • Helps keep unused code out of the system (unwritten) • Makes codebase more maintainable – via regression testing
  • 11.
    © 2013 iZenBridge| CONFIDENTIAL The TDD Cycle  Red  Green  Clean Test Code Refactor
  • 12.
    © 2013 iZenBridge| CONFIDENTIAL Three Laws/ Rules of TDD You will not write any production code until you have written a failing unit test. First Law
  • 13.
    © 2013 iZenBridge| CONFIDENTIAL Three laws of TDD You will not write more of a unit test than is sufficient to fail, and not compiling is failing Second Law
  • 14.
    © 2013 iZenBridge| CONFIDENTIAL Three laws of TDD You will not write more production code that is sufficient to pass the currently failing test. Third Law
  • 15.
    © 2013 iZenBridge| CONFIDENTIAL Misconceptions About TDD • Writing code first, then tests is same as TDD • TDD isn’t useful for designing architecture • Takes too much time • Too complex to learn and implement • TDD is only good for small projects
  • 16.
    © 2013 iZenBridge| CONFIDENTIAL
  • 17.
    © 2013 iZenBridge| CONFIDENTIAL Let’s Build Something Now!
  • 18.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator – TDD Exercise Define Scope: • Supported operators? • Acceptable characters? • Whitespace? • Max length of expression – number of operations? • Max length of each number? • Fractions? • Parenthesis?
  • 19.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) Time to start Failing! • Reminders: • Test, Code, Refactor – REPEAT until Done! • Add feature layers one by one, in small manageable increments • Setup • Eclipse for Java Development • JDK • Team formation
  • 20.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 1. Two literal addition A + B
  • 21.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 2. Multiple literal addition A + B + C A + B + C + D
  • 22.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 3. Combination of addition and subtraction A + B – C or A – B + C
  • 23.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 4. Simple multiplication A * B A * B * C
  • 24.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 5. Simple division A / B A / B / C
  • 25.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 6. Combination of multiplication and division A * B / C A / B * C Does order matter?
  • 26.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 7. Combination of all four A + B – C * D / E Order does matter here!
  • 27.
    © 2013 iZenBridge| CONFIDENTIAL String Calculator (continued) 8. Invalid expressions • Banned chars - alpha, parenthesis, special chars • Space between a number • Two operators clubbed together • First number negative • Invalid decimal number
  • 28.
    © 2013 iZenBridge| CONFIDENTIAL What Next? Certified Scrum Developer (CSD) A 3-day course certified by Scrum Alliance that focuses on specialized Agile engineering skills:  Test Driven Development (TDD)  ATDD, BDD – Selenium/ Cucumber  Continuous Integration – Jenkins  Agile Design and Architecture  Refactoring  Collaboration
  • 29.
    © 2013 iZenBridge| CONFIDENTIAL References  Test Driven Development: By Example - Kent Beck  Succeeding with Agile - Mike Cohn  Test Driven: Practical TDD and Acceptance TDD for Java Developers - Lasse Koskela
  • 30.
    © 2013 iZenBridge| CONFIDENTIAL Stay Connected YouTube www.youtube.com/izenbridge LinkedIn Group PMI-ACP: Agile Certification Made Easy Saket.Bansal@iZenBridge.com SunjayKumar@gmail.com www.iZenBridge.com forum.iZenBridge.com