TDD Overview

  • 4,779 views
Uploaded on

Million Feet Overview of Test Driven Development. (not a very technical presentation).

Million Feet Overview of Test Driven Development. (not a very technical presentation).

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,779
On Slideshare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
273
Comments
0
Likes
10

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Test Driven Development Embrace Uncertainty Naresh Jain Twitter: @nashjain http://blogs.agilefaqs.com Licensed Under Creative Commons by Naresh Jain Friday, October 2, 2009 1
  • 2. TDD Rhythm Test, Code, Refactor Friday, October 2, 2009 2
  • 3. TDD Rhythm Test, Code, Refactor Add a Test Friday, October 2, 2009 2
  • 4. TDD Rhythm Test, Code, Refactor Add a Test Run the Test Friday, October 2, 2009 2
  • 5. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Friday, October 2, 2009 2
  • 6. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Friday, October 2, 2009 2
  • 7. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Friday, October 2, 2009 2
  • 8. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Run the Test Friday, October 2, 2009 2
  • 9. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Friday, October 2, 2009 2
  • 10. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Pass Friday, October 2, 2009 2
  • 11. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Pass Refactor Friday, October 2, 2009 2
  • 12. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Pass Refactor Friday, October 2, 2009 2
  • 13. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Pass Refactor Friday, October 2, 2009 2
  • 14. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Fail Run the Test Pass Refactor Friday, October 2, 2009 2
  • 15. But.... Friday, October 2, 2009 3
  • 16. rk? e? Ho a Wo m her wt oS E xtr probl e tar a t? th ere Wh Is o? W hen ? ROI? Pro duc tivit y? Friday, October 2, 2009 3
  • 17. Continuum Friday, October 2, 2009 4
  • 18. Friday, October 2, 2009 5
  • 19. Post Agile New to Agile Friday, October 2, 2009 5
  • 20. Post Agile Expert TDD New to TDD Practitioners New to Agile Friday, October 2, 2009 5
  • 21. Me Friday, October 2, 2009 6
  • 22. Friday, October 2, 2009 7
  • 23. Mumbai Friday, October 2, 2009 8
  • 24. Friday, October 2, 2009 9
  • 25. Friday, October 2, 2009 10
  • 26. We don’t travel like this Friday, October 2, 2009 11
  • 27. We are getting there... Friday, October 2, 2009 12
  • 28. Tech Talks! Friday, October 2, 2009 13
  • 29. Friday, October 2, 2009 14
  • 30. Friday, October 2, 2009 15
  • 31. Friday, October 2, 2009 16
  • 32. Warmup Scenario Friday, October 2, 2009 17
  • 33. Friday, October 2, 2009 18
  • 34. Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed? Friday, October 2, 2009 18
  • 35. Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed? Going out for Movie (THX sound and Digital projection) Friday, October 2, 2009 18
  • 36. Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed? Going out for Movie (THX sound and Digital projection) Going out for meal (one veg.) Friday, October 2, 2009 18
  • 37. Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed? Going out for Movie (THX sound and Digital projection) Going out for meal (one veg.) Going shopping ($50) [10 Minutes] Friday, October 2, 2009 18
  • 38. Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed? Going out for Movie (THX sound and Digital projection) Going out for meal (one veg.) Going shopping ($50) [10 Minutes] Present back to the group your findings. [3 minutes per group] Friday, October 2, 2009 18
  • 39. Acceptance Criteria and Tests A critical piece of Agile Friday, October 2, 2009 19
  • 40. Acceptance Criteria Is a set of conditions that the Story must meet for it to be accepted as complete Is typically provided by the customer or product owner. Is not a replacement for conversation. Is one of the results of the conversation Acceptance Criteria are NOT tests Friday, October 2, 2009 20
  • 41. Given [Precondition] When [Actor + Action] Then [Observable Result] Friday, October 2, 2009 21
  • 42. Acceptance Criteria Examples (data + scenarios) Acceptance Tests Friday, October 2, 2009 22
  • 43. Acceptance Criteria + Examples (data + scenarios) Acceptance Tests Friday, October 2, 2009 22
  • 44. Demo Roman Numerals to Decimal Conversion Example Friday, October 2, 2009 23
  • 45. 1 May 1 Jul 1 Sep 1 Nov Analysis Design Implementation ERD DFD DD ST Friday, October 2, 2009 24
  • 46. Business Facing Are we building the right product? Are we building the product right? Technology/Implementation Facing Friday, October 2, 2009 25
  • 47. Brian Marick’s Test Categorization Business Facing Supports Programming Critique product Technology/Implementation Facing Friday, October 2, 2009 26
  • 48. It Helps to think... Business Facing Drives Development Critique product Technology/Implementation Facing Friday, October 2, 2009 27
  • 49. It Helps to think... Business Facing Drives Development Critique product Unit Testing Technology/Implementation Facing Friday, October 2, 2009 27
  • 50. It Helps to think... Business Facing Acceptance Testing Drives Development Low-fi prototypes Critique product Unit Testing Technology/Implementation Facing Friday, October 2, 2009 27
  • 51. It Helps to think... Business Facing Acceptance Testing Exploratory Testing Drives Development Low-fi prototypes UI and Usability Testing Critique product Unit Testing Technology/Implementation Facing Friday, October 2, 2009 27
  • 52. It Helps to think... Business Facing Acceptance Testing Exploratory Testing Drives Development Low-fi prototypes UI and Usability Testing Critique product Performance Testing Unit Testing System Tests Technology/Implementation Facing Friday, October 2, 2009 27
  • 53. Acceptance Test Driven Friday, October 2, 2009 28
  • 54. Acceptance Test Driven Story Friday, October 2, 2009 28
  • 55. Acceptance Test Driven Acceptance Criteria Story Friday, October 2, 2009 28
  • 56. Acceptance Test Driven Iteration Acceptance Criteria Story Friday, October 2, 2009 28
  • 57. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Story Friday, October 2, 2009 28
  • 58. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Friday, October 2, 2009 28
  • 59. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Automated Acceptance Tests Friday, October 2, 2009 28
  • 60. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Automated Acceptance Tests Exploratory Testing Friday, October 2, 2009 28
  • 61. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Automated Acceptance Tests Acceptance Exploratory Criteria Testing Friday, October 2, 2009 28
  • 62. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Automated UI Tests Automated Acceptance Tests Acceptance Exploratory Criteria Testing Friday, October 2, 2009 28
  • 63. Acceptance Test Driven Iteration Automated Acceptance P Acceptance Tests E Criteria R F O Automated R Story Unit Test M T Automated E E UI Tests N S C T E S Automated Acceptance Tests Acceptance Exploratory Criteria Testing Friday, October 2, 2009 28
  • 64. Mike Cohn’s Testing Pyramid Friday, October 2, 2009 29
  • 65. Mike Cohn’s Testing Pyramid GUI Tests Friday, October 2, 2009 29
  • 66. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Friday, October 2, 2009 29
  • 67. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Acceptance Tests Friday, October 2, 2009 29
  • 68. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Acceptance At least one per story Tools: Fit, FitNesse, RSpec, Cucumber Tests Friday, October 2, 2009 29
  • 69. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Acceptance At least one per story Tools: Fit, FitNesse, RSpec, Cucumber Tests Unit Tests Friday, October 2, 2009 29
  • 70. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Acceptance At least one per story Tools: Fit, FitNesse, RSpec, Cucumber Tests At least one per class or module Tools: xUnit, TestNG Unit Tests Friday, October 2, 2009 29
  • 71. Acceptance Tests View UI Model and Presenter Business Tier Data Store Friday, October 2, 2009 30
  • 72. Why care about TDD? Friday, October 2, 2009 31
  • 73. Friday, October 2, 2009 32
  • 74. # of Lines of Code? Friday, October 2, 2009 33
  • 75. # of Story Points (estimates)? Friday, October 2, 2009 34
  • 76. Friday, October 2, 2009 35
  • 77. # of Features developed? Friday, October 2, 2009 35
  • 78. # of Features tested? Friday, October 2, 2009 35
  • 79. # of Features deployed? Friday, October 2, 2009 35
  • 80. # of Features used actively? Friday, October 2, 2009 35
  • 81. What about Maintenance? Friday, October 2, 2009 36
  • 82. Stay away from (time hungry) debugger Friday, October 2, 2009 37
  • 83. Manual (monkey) Checking by Developers and Tester Friday, October 2, 2009 38
  • 84. Maintain Focus Friday, October 2, 2009 39
  • 85. Reduce Wastage: Hand Overs Friday, October 2, 2009 40
  • 86. Communication Friday, October 2, 2009 41
  • 87. Living, up-to-date specification Friday, October 2, 2009 42
  • 88. Communicate Design Decisions Friday, October 2, 2009 43
  • 89. Learning: Listen to your code Friday, October 2, 2009 44
  • 90. Baby Steps: Slow down and think Friday, October 2, 2009 45
  • 91. Confidence Friday, October 2, 2009 46
  • 92. Testable Code by Design + Safety Net Friday, October 2, 2009 47
  • 93. Loosely Coupled Design Friday, October 2, 2009 48
  • 94. Refactoring Friday, October 2, 2009 49
  • 95. Test Driven Design Before you take the plunge Friday, October 2, 2009 50
  • 96. Evolutionary Design Friday, October 2, 2009 51
  • 97. System Metaphor Friday, October 2, 2009 52
  • 98. Thin Slicing Friday, October 2, 2009 53
  • 99. Interaction Design Friday, October 2, 2009 54
  • 100. Tracer Bullets Friday, October 2, 2009 55
  • 101. Avatars of TDD Rule of Diversity Distrust all claims for “One True Way” Friday, October 2, 2009 56
  • 102. Business Facing Drives Development Critique product Inside Out Outside In Technology/Implementation Facing Brian Marick’s Test Categorization Friday, October 2, 2009 57
  • 103. Veterinarian Information System Friday, October 2, 2009 58
  • 104. Outside In: ATDD Fitnesse Document: Assertions: 17 right, 0 wrong, 0 ignored, 0 exceptions com.vis.billing.fixtures.PaidCashBill procedure details on the bill account details name cost account number patient name owner name Routine Office Visit 250 1001 Fluffy Dave Atkins Rabies Vaccination 50 procedure details pay Cash name cost patient name? owner name? account number? bill no? payment method? amount paid? Routine Office Visit 250 Fluffy Dave Atkins 1001 1 Cash 300 Rabies Vaccination 50 bill check paid true account number? owner name? patient name? total? paid? 1001 Dave Atkins Fluffy 300 false check total 0 Friday, October 2, 2009 59
  • 105. Outside In: Output Friday, October 2, 2009 60
  • 106. ATDD: Another Example Acceptance test: class FluffyTest < Test::Unit::TestCase def test_examination_and_shots vet = Veterinarian.new clinic = Clinic.new "Main Line health" dave = Owner.new "Dave" fluffy = Patient.new "Fluffy" dave.has fluffy visit = clinic.visit(fluffy, vet) do |v| v.procedure "Rabies vaccination", 50 end invoice = visit.invoice assert_equal invoice.to_s, <<-INVOICE Routine visit: $200 Rabies vaccination: $50 Total: $250 INVOICE receipt = clinic.pay_for visit, 100 assert_equal receipt.to_s, <<-RECEIPT Paid $100 for Routine visit Paid $0 for Rabies vaccination Outstanding: $150 RECEIPT end end Friday, October 2, 2009 61
  • 107. Outside In: Output Friday, October 2, 2009 62
  • 108. Inside Out: Unit TDD public class ClinicTest { private Clinic clinic = new Clinic(); @Test public class BillableTest { public void amountOnTheReceiptShouldMatchBillableAmount() throws Exception { Billable billable = new Billable() { private static final Account daveSAccount = new Account(101, "Dave"); public int totalAmount() { return 0; } private static final List<Service> services = new ArrayList<Service>(); }; Account dave = new Account(101, "Dave"); @Test public void totalBillableAmountShouldBeZeroIfNoServicesAreProvided() { Receipt rcpt = clinic.payCash(dave, billable); Billable bill = new Bill(daveSAccount, services); assertEquals("Amount on receipt does match procedure cost", billable.totalAmount(), assertEquals("Total amount is not Zero", 0, bill.totalAmount()); rcpt.getAmount()); } } @Test @Test public void totalBillableAmountShouldBeTotalOfEachServiceProvided() { public void customerPayesBillableAmountForCashTransaction() throws Exception { services.add(new Procedure("Rabies Vaccination", 250)); final int billableAmount = 56; services.add(new Procedure("Regular office Visit", 50)); class AmountCharged { int charged; }; final AmountCharged charged = new AmountCharged(); Billable bill = new Bill(daveSAccount, services); Billable billable = new Billable() { assertEquals("Total Amount is not 300", 300, bill.totalAmount()); public int totalAmount() { } return billableAmount; } @After }; public void cleanUp() { services.clear(); Account dave = new Account(101, "Dave") { } public void charge(int amount) { } charged.charged = amount; } }; clinic.payCash(dave, billable); assertEquals("Account is not charged billable amount", billableAmount,charged.charged); } } Friday, October 2, 2009 63
  • 109. Inside Out: Output Friday, October 2, 2009 64
  • 110. Inside Out: Another Example public class ChargeAccountForServices { private static final Billable bill = createMock(Billable.class); private static final Accountable account = createMock(Accountable.class); private static final Clinic clinic = new Clinic(); @Before public void setUp() { reset(account); @Test reset(bill); public void shouldHaveZeroAmountDueOnReceiptIfCompletePaymentIsMade() { } expect(bill.amount()).andReturn(300); replay(bill); @Test Receipt receipt = clinic.pay(300, bill, account); public void shouldMakePaymentsAgainstAnAccount() { verify(bill); account.paid(bill); assertEquals(300, receipt.amount()); replay(account); assertEquals(0, receipt.amountDue()); clinic.pay(300, bill, account); } verify(account); } @Test public void shouldDisplayAmountDueOnTheReceiptIfIncompletePaymentIsMade() { expect(bill.amount()).andReturn(500); replay(bill); Receipt receipt = clinic.pay(300, bill, account); verify(bill); assertEquals(300, receipt.amount()); assertEquals(200, receipt.amountDue()); } } Friday, October 2, 2009 65
  • 111. public class CreateBillForClientAccount { private static final List<Service> services = new ArrayList<Service>(); private static final Accountable account = createMock(Accountable.class); private Bill bill; @Before public void setUp() { reset(account); } @Test public void shouldThrowExceptionIfAccountIsNotDueForPayment() { @Test expect(account.isPaymentDue()).andReturn(false); public void shouldCreateABillWithTheTotalCostOfAllTheServices() { replay(account); IMocksControl control = createControl(); try { Service rabiesVaccination = control.createMock(Service.class); new Bill(account, null); Service routineVisit = control.createMock(Service.class); } catch (NoPaymentDueException e) { services.add(rabiesVaccination); // expected services.add(routineVisit); } expect(account.isPaymentDue()).andReturn(true); verify(account); expect(account.unpaidServices()).andReturn(services); } bill(); @After expect(rabiesVaccination.cost()).andReturn(250); public void cleanUp() { expect(routineVisit.cost()).andReturn(50); services.clear(); } control.replay(); assertEquals(300, bill.amount()); control.verify(); } private void bill() throws NoPaymentDueException { replay(account); bill = new Bill(account, null); verify(account); } } Friday, October 2, 2009 66
  • 112. Inside Out: Output Friday, October 2, 2009 67
  • 113. Coffee Vending Machine How would you develop it? Friday, October 2, 2009 68
  • 114. Feedback Friday, October 2, 2009 69
  • 115. Friday, October 2, 2009 70
  • 116. Friday, October 2, 2009 71
  • 117. Friday, October 2, 2009 72
  • 118. Visualizing Proficiency Industrial Logic’s e-learning Automated Analysis of Lab Exercises http://industriallogic.com/elearning/ Friday, October 2, 2009 73
  • 119. Friday, October 2, 2009 74
  • 120. Friday, October 2, 2009 75
  • 121. Friday, October 2, 2009 76
  • 122. Friday, October 2, 2009 77
  • 123. Friday, October 2, 2009 78
  • 124. Friday, October 2, 2009 79
  • 125. Tools & Practices Friday, October 2, 2009 80
  • 126. Pair Programming Friday, October 2, 2009 81
  • 127. Continuous Integration Friday, October 2, 2009 82
  • 128. Friday, October 2, 2009 83
  • 129. Coding Convention + Static Code Analysis Friday, October 2, 2009 84
  • 130. Checkstyle Friday, October 2, 2009 85
  • 131. Code Coverage Friday, October 2, 2009 86
  • 132. Cobertura Friday, October 2, 2009 87
  • 133. DB Management Friday, October 2, 2009 88
  • 134. Migrate4j Bering Friday, October 2, 2009 89
  • 135. Questions? naresh@agilefaqs.com Friday, October 2, 2009 90