0
Test Driven Development
                               Embrace Uncertainty



                                 Naresh Jain...
TDD Rhythm
                          Test, Code, Refactor




Friday, October 2, 2009                          2
TDD Rhythm
                          Test, Code, Refactor
                                 Add a Test




Friday, October ...
TDD Rhythm
                          Test, Code, Refactor
                                  Add a Test



                ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
TDD Rhythm
                          Test, Code, Refactor
                                       Add a Test

             ...
But....


Friday, October 2, 2009             3
rk?                                 e?
                                         Ho                         a Wo           ...
Continuum


Friday, October 2, 2009               4
Friday, October 2, 2009   5
Post Agile




                          New to Agile


Friday, October 2, 2009                  5
Post Agile



          Expert TDD
                                         New to TDD
          Practitioners




       ...
Me


Friday, October 2, 2009        6
Friday, October 2, 2009   7
Mumbai
Friday, October 2, 2009            8
Friday, October 2, 2009   9
Friday, October 2, 2009   10
We don’t travel like this




Friday, October 2, 2009                      11
We are getting there...




Friday, October 2, 2009                         12
Tech Talks!




Friday, October 2, 2009                 13
Friday, October 2, 2009   14
Friday, October 2, 2009   15
Friday, October 2, 2009   16
Warmup Scenario


Friday, October 2, 2009              17
Friday, October 2, 2009   18
Pick one scenario and in relation to your scenario, what are the
           specific observable results that will tell you ...
Pick one scenario and in relation to your scenario, what are the
           specific observable results that will tell you ...
Pick one scenario and in relation to your scenario, what are the
           specific observable results that will tell you ...
Pick one scenario and in relation to your scenario, what are the
           specific observable results that will tell you ...
Pick one scenario and in relation to your scenario, what are the
           specific observable results that will tell you ...
Acceptance Criteria
                              and Tests
                              A critical piece of Agile




Fr...
Acceptance Criteria
                Is a set of conditions that the Story must meet for it to be accepted
                ...
Given [Precondition]

                          When [Actor + Action]

                          Then [Observable Result]
...
Acceptance Criteria

                          Examples (data + scenarios)


                                    Acceptanc...
Acceptance Criteria

               + Examples (data + scenarios)


                            Acceptance Tests


Friday,...
Demo
                          Roman Numerals to Decimal Conversion Example




Friday, October 2, 2009                   ...
1 May               1 Jul               1 Sep          1 Nov

                           Analysis

                       ...
Business Facing




                          Are we building the right product?




                          Are we buil...
Brian Marick’s
                                      Test Categorization
                                                 ...
It Helps to think...
                                           Business Facing
         Drives Development




          ...
It Helps to think...
                                                 Business Facing
         Drives Development




    ...
It Helps to think...
                                                    Business Facing



                              ...
It Helps to think...
                                                    Business Facing



                              ...
It Helps to think...
                                                    Business Facing



                              ...
Acceptance Test Driven




Friday, October 2, 2009                    28
Acceptance Test Driven


        Story




Friday, October 2, 2009                    28
Acceptance Test Driven

                          Acceptance
                           Criteria


        Story




Frida...
Acceptance Test Driven
                                       Iteration



                          Acceptance
          ...
Acceptance Test Driven
                                         Iteration
                                       Automated...
Acceptance Test Driven
                                                  Iteration
                                       ...
Acceptance Test Driven
                                                  Iteration
                                       ...
Acceptance Test Driven
                                                  Iteration
                                       ...
Acceptance Test Driven
                                                  Iteration
                                       ...
Acceptance Test Driven
                                                  Iteration
                                       ...
Acceptance Test Driven
                                                  Iteration
                                       ...
Mike Cohn’s Testing Pyramid




Friday, October 2, 2009           29
Mike Cohn’s Testing Pyramid
                          GUI
                          Tests




Friday, October 2, 2009     ...
Mike Cohn’s Testing Pyramid
                                                 Small in Number
                          GUI...
Mike Cohn’s Testing Pyramid
                                                      Small in Number
                        ...
Mike Cohn’s Testing Pyramid
                                                      Small in Number
                        ...
Mike Cohn’s Testing Pyramid
                                                      Small in Number
                        ...
Mike Cohn’s Testing Pyramid
                                                      Small in Number
                        ...
Acceptance Tests                          View


                                                                   UI
   ...
Why care about TDD?



Friday, October 2, 2009                     31
Friday, October 2, 2009   32
# of Lines of Code?



Friday, October 2, 2009                         33
# of Story Points
                            (estimates)?


Friday, October 2, 2009                       34
Friday, October 2, 2009   35
# of Features developed?



Friday, October 2, 2009               35
# of Features tested?



Friday, October 2, 2009            35
# of Features deployed?



Friday, October 2, 2009              35
# of Features used actively?



Friday, October 2, 2009                  35
What about Maintenance?



Friday, October 2, 2009             36
Stay away from (time
                            hungry) debugger


Friday, October 2, 2009                          37
Manual (monkey)
                          Checking by
                      Developers and Tester


Friday, October 2, 200...
Maintain Focus



Friday, October 2, 2009                    39
Reduce Wastage: Hand Overs



Friday, October 2, 2009   40
Communication




Friday, October 2, 2009                   41
Living, up-to-date
                             specification


Friday, October 2, 2009                        42
Communicate Design
                             Decisions


Friday, October 2, 2009                        43
Learning:
                          Listen to your code


Friday, October 2, 2009                         44
Baby Steps:
                          Slow down and think


Friday, October 2, 2009                         45
Confidence




Friday, October 2, 2009               46
Testable Code by Design
                    + Safety Net


Friday, October 2, 2009                 47
Loosely Coupled Design



Friday, October 2, 2009                  48
Refactoring



Friday, October 2, 2009                 49
Test Driven Design
                            Before you take the plunge




Friday, October 2, 2009                     ...
Evolutionary Design



Friday, October 2, 2009                         51
System Metaphor



Friday, October 2, 2009                     52
Thin Slicing



Friday, October 2, 2009                  53
Interaction Design



Friday, October 2, 2009                        54
Tracer Bullets



Friday, October 2, 2009                    55
Avatars of TDD
                                     Rule of Diversity
                          Distrust all claims for “O...
Business Facing
  Drives Development




                                                                          Critiqu...
Veterinarian
                          Information System



Friday, October 2, 2009                        58
Outside In: ATDD
   Fitnesse Document:
   Assertions: 17 right, 0 wrong, 0 ignored, 0 exceptions


  com.vis.billing.fixtu...
Outside In: Output




Friday, October 2, 2009                        60
ATDD: Another Example
                          Acceptance test:
                          class FluffyTest < Test::Unit::...
Outside In: Output




Friday, October 2, 2009                        62
Inside Out: Unit TDD
     public class ClinicTest {
       private Clinic clinic = new Clinic();

       @Test            ...
Inside Out: Output




Friday, October 2, 2009                        64
Inside Out: Another Example
  public class ChargeAccountForServices {
    private static final Billable bill = createMock(...
public class CreateBillForClientAccount {
     private static final List<Service> services = new ArrayList<Service>();
   ...
Inside Out: Output




Friday, October 2, 2009                        67
Coffee Vending Machine
                          How would you develop it?




Friday, October 2, 2009                    ...
Feedback



Friday, October 2, 2009              69
Friday, October 2, 2009   70
Friday, October 2, 2009   71
Friday, October 2, 2009   72
Visualizing Proficiency
                             Industrial Logic’s
                                e-learning
        ...
Friday, October 2, 2009   74
Friday, October 2, 2009   75
Friday, October 2, 2009   76
Friday, October 2, 2009   77
Friday, October 2, 2009   78
Friday, October 2, 2009   79
Tools & Practices


Friday, October 2, 2009                   80
Pair Programming



Friday, October 2, 2009                      81
Continuous Integration



Friday, October 2, 2009                     82
Friday, October 2, 2009   83
Coding Convention
                                   +
                          Static Code Analysis


Friday, October 2,...
Checkstyle




Friday, October 2, 2009   85
Code Coverage



Friday, October 2, 2009                   86
Cobertura




Friday, October 2, 2009               87
DB Management



Friday, October 2, 2009                   88
Migrate4j
                          Bering



Friday, October 2, 2009                        89
Questions?

                          naresh@agilefaqs.com

Friday, October 2, 2009                          90
Upcoming SlideShare
Loading in...5
×

TDD Overview

5,390

Published on

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

Published in: Technology, Business
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,390
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
284
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

Transcript of "TDD Overview"

  1. 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. 2. TDD Rhythm Test, Code, Refactor Friday, October 2, 2009 2
  3. 3. TDD Rhythm Test, Code, Refactor Add a Test Friday, October 2, 2009 2
  4. 4. TDD Rhythm Test, Code, Refactor Add a Test Run the Test Friday, October 2, 2009 2
  5. 5. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Friday, October 2, 2009 2
  6. 6. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Friday, October 2, 2009 2
  7. 7. TDD Rhythm Test, Code, Refactor Add a Test Pass Run the Test Fail Make a little change Friday, October 2, 2009 2
  8. 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. 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. 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. 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. 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. 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. 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. 15. But.... Friday, October 2, 2009 3
  16. 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. 17. Continuum Friday, October 2, 2009 4
  18. 18. Friday, October 2, 2009 5
  19. 19. Post Agile New to Agile Friday, October 2, 2009 5
  20. 20. Post Agile Expert TDD New to TDD Practitioners New to Agile Friday, October 2, 2009 5
  21. 21. Me Friday, October 2, 2009 6
  22. 22. Friday, October 2, 2009 7
  23. 23. Mumbai Friday, October 2, 2009 8
  24. 24. Friday, October 2, 2009 9
  25. 25. Friday, October 2, 2009 10
  26. 26. We don’t travel like this Friday, October 2, 2009 11
  27. 27. We are getting there... Friday, October 2, 2009 12
  28. 28. Tech Talks! Friday, October 2, 2009 13
  29. 29. Friday, October 2, 2009 14
  30. 30. Friday, October 2, 2009 15
  31. 31. Friday, October 2, 2009 16
  32. 32. Warmup Scenario Friday, October 2, 2009 17
  33. 33. Friday, October 2, 2009 18
  34. 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. 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. 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. 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. 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. 39. Acceptance Criteria and Tests A critical piece of Agile Friday, October 2, 2009 19
  40. 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. 41. Given [Precondition] When [Actor + Action] Then [Observable Result] Friday, October 2, 2009 21
  42. 42. Acceptance Criteria Examples (data + scenarios) Acceptance Tests Friday, October 2, 2009 22
  43. 43. Acceptance Criteria + Examples (data + scenarios) Acceptance Tests Friday, October 2, 2009 22
  44. 44. Demo Roman Numerals to Decimal Conversion Example Friday, October 2, 2009 23
  45. 45. 1 May 1 Jul 1 Sep 1 Nov Analysis Design Implementation ERD DFD DD ST Friday, October 2, 2009 24
  46. 46. Business Facing Are we building the right product? Are we building the product right? Technology/Implementation Facing Friday, October 2, 2009 25
  47. 47. Brian Marick’s Test Categorization Business Facing Supports Programming Critique product Technology/Implementation Facing Friday, October 2, 2009 26
  48. 48. It Helps to think... Business Facing Drives Development Critique product Technology/Implementation Facing Friday, October 2, 2009 27
  49. 49. It Helps to think... Business Facing Drives Development Critique product Unit Testing Technology/Implementation Facing Friday, October 2, 2009 27
  50. 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. 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. 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. 53. Acceptance Test Driven Friday, October 2, 2009 28
  54. 54. Acceptance Test Driven Story Friday, October 2, 2009 28
  55. 55. Acceptance Test Driven Acceptance Criteria Story Friday, October 2, 2009 28
  56. 56. Acceptance Test Driven Iteration Acceptance Criteria Story Friday, October 2, 2009 28
  57. 57. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Story Friday, October 2, 2009 28
  58. 58. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Friday, October 2, 2009 28
  59. 59. Acceptance Test Driven Iteration Automated Acceptance Acceptance Tests Criteria Automated Story Unit Test Automated Acceptance Tests Friday, October 2, 2009 28
  60. 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. 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. 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. 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. 64. Mike Cohn’s Testing Pyramid Friday, October 2, 2009 29
  65. 65. Mike Cohn’s Testing Pyramid GUI Tests Friday, October 2, 2009 29
  66. 66. Mike Cohn’s Testing Pyramid Small in Number GUI Tools: Selenium, Sahi, Watir, Abbot, Frankenstein Tests Friday, October 2, 2009 29
  67. 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. 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. 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. 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. 71. Acceptance Tests View UI Model and Presenter Business Tier Data Store Friday, October 2, 2009 30
  72. 72. Why care about TDD? Friday, October 2, 2009 31
  73. 73. Friday, October 2, 2009 32
  74. 74. # of Lines of Code? Friday, October 2, 2009 33
  75. 75. # of Story Points (estimates)? Friday, October 2, 2009 34
  76. 76. Friday, October 2, 2009 35
  77. 77. # of Features developed? Friday, October 2, 2009 35
  78. 78. # of Features tested? Friday, October 2, 2009 35
  79. 79. # of Features deployed? Friday, October 2, 2009 35
  80. 80. # of Features used actively? Friday, October 2, 2009 35
  81. 81. What about Maintenance? Friday, October 2, 2009 36
  82. 82. Stay away from (time hungry) debugger Friday, October 2, 2009 37
  83. 83. Manual (monkey) Checking by Developers and Tester Friday, October 2, 2009 38
  84. 84. Maintain Focus Friday, October 2, 2009 39
  85. 85. Reduce Wastage: Hand Overs Friday, October 2, 2009 40
  86. 86. Communication Friday, October 2, 2009 41
  87. 87. Living, up-to-date specification Friday, October 2, 2009 42
  88. 88. Communicate Design Decisions Friday, October 2, 2009 43
  89. 89. Learning: Listen to your code Friday, October 2, 2009 44
  90. 90. Baby Steps: Slow down and think Friday, October 2, 2009 45
  91. 91. Confidence Friday, October 2, 2009 46
  92. 92. Testable Code by Design + Safety Net Friday, October 2, 2009 47
  93. 93. Loosely Coupled Design Friday, October 2, 2009 48
  94. 94. Refactoring Friday, October 2, 2009 49
  95. 95. Test Driven Design Before you take the plunge Friday, October 2, 2009 50
  96. 96. Evolutionary Design Friday, October 2, 2009 51
  97. 97. System Metaphor Friday, October 2, 2009 52
  98. 98. Thin Slicing Friday, October 2, 2009 53
  99. 99. Interaction Design Friday, October 2, 2009 54
  100. 100. Tracer Bullets Friday, October 2, 2009 55
  101. 101. Avatars of TDD Rule of Diversity Distrust all claims for “One True Way” Friday, October 2, 2009 56
  102. 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. 103. Veterinarian Information System Friday, October 2, 2009 58
  104. 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. 105. Outside In: Output Friday, October 2, 2009 60
  106. 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. 107. Outside In: Output Friday, October 2, 2009 62
  108. 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. 109. Inside Out: Output Friday, October 2, 2009 64
  110. 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. 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. 112. Inside Out: Output Friday, October 2, 2009 67
  113. 113. Coffee Vending Machine How would you develop it? Friday, October 2, 2009 68
  114. 114. Feedback Friday, October 2, 2009 69
  115. 115. Friday, October 2, 2009 70
  116. 116. Friday, October 2, 2009 71
  117. 117. Friday, October 2, 2009 72
  118. 118. Visualizing Proficiency Industrial Logic’s e-learning Automated Analysis of Lab Exercises http://industriallogic.com/elearning/ Friday, October 2, 2009 73
  119. 119. Friday, October 2, 2009 74
  120. 120. Friday, October 2, 2009 75
  121. 121. Friday, October 2, 2009 76
  122. 122. Friday, October 2, 2009 77
  123. 123. Friday, October 2, 2009 78
  124. 124. Friday, October 2, 2009 79
  125. 125. Tools & Practices Friday, October 2, 2009 80
  126. 126. Pair Programming Friday, October 2, 2009 81
  127. 127. Continuous Integration Friday, October 2, 2009 82
  128. 128. Friday, October 2, 2009 83
  129. 129. Coding Convention + Static Code Analysis Friday, October 2, 2009 84
  130. 130. Checkstyle Friday, October 2, 2009 85
  131. 131. Code Coverage Friday, October 2, 2009 86
  132. 132. Cobertura Friday, October 2, 2009 87
  133. 133. DB Management Friday, October 2, 2009 88
  134. 134. Migrate4j Bering Friday, October 2, 2009 89
  135. 135. Questions? naresh@agilefaqs.com Friday, October 2, 2009 90
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×