Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Fake it Outside-In TDD IT.A.K.E 2018

208 views

Published on

These are the slides of my "Fake it Outside-In TDD" session at the I T.A.K.E unconference. Do not miss to check out the referenced screencasts that illustrate the approach very well: https://www.youtube.com/playlist?list=PL_ueet93U84VIy8O7U4dUV0GyGvuzFAt8

Published in: Software
  • Be the first to comment

Fake it Outside-In TDD IT.A.K.E 2018

  1. 1. FAKE IT OUTSIDE-IN TDD David Völkel 08.06.2018 @ IT.A.K.E Unconference
  2. 2. @DAVIDVOELKEL @codecentric @softwerkskammer #TDD
  3. 3. INFLUENCES 2003 Kent Beck’s "Fake It" Pattern 2009 #GOOS’s "Outside-In" Design 2013 Emily Bache 
 "Outside-In development with Double Loop TDD" 2014 Justin Searls "The Failures of 'Intro to TDD'" COMBINATION 2015 Dimitry Polivaev Outside-In with faked Data 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement
  4. 4. INFLUENCES 2003 Kent Beck’s "Fake It" Pattern 2009 #GOOS’s "Outside-In" Design 2013 Emily Bache 
 "Outside-In development with Double Loop TDD" 2014 Justin Searls "The Failures of 'Intro to TDD'" COMBINATION 2015 Dimitry Polivaev Outside-In with faked Data 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement
  5. 5. INFLUENCES 2003 Kent Beck’s "Fake It" Pattern 2009 #GOOS’s "Outside-In" Design COMBINATION FAKE IT OUTSIDE-IN TDD
  6. 6. FAKE IT OUTSIDE-IN TDD INFLUENCES 2003 Kent Beck’s "Fake It" Pattern 2009 #GOOS’s "Outside-In" Design 2013 Emily Bache 
 "Outside-In development with Double Loop TDD" 2014 Justin Searls "The Failures of 'Intro to TDD'" 2017 Llewelyn Falco „Extreme: Fake it Till you Make It“ FAKE IT OUTSIDE-IN TDD
  7. 7. WHY? Outside-In => YAGNI free design
  8. 8. WHY? Outside-In => YAGNI free design Avoid mocking drawbacks - Readability - Refactorability
  9. 9. WHY? Outside-In => YAGNI free design Avoid mocking drawbacks - Readability - Refactorability Later: Smaller steps
  10. 10. AGENDA Theory Building Blocks Fake It Outside-In Practice Mob Programming Session Reflect Retro Trade-Offs
  11. 11. BUILDING BLOCKS
  12. 12. INTEGRATION OPERATION SEGREGATION PRINCIPLE *"Integration Operation Segregation Principle", Ralf Westphal "Die kniffligen Fälle beim Testen - Sichtbarkeit", Stefan Lieser *
  13. 13. INTEGRATION OPERATION SEGREGATION PRINCIPLE public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); Account account = customer.account(); String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; String content = "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; mailService.sendMail(email, content); }
  14. 14. OPERATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); Account account = customer.account(); String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; String content = "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; mailService.sendMail(email, content); } INTEGRATION OPERATION SEGREGATION PRINCIPLE
  15. 15. INTEGRATION INTEGRATION OPERATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); Account account = customer.account(); String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; String content = "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; mailService.sendMail(email, content); } INTEGRATION OPERATION SEGREGATION PRINCIPLE
  16. 16. INTEGRATION INTEGRATION OPERATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); Account account = customer.account(); String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; String content = "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; mailService.sendMail(email, content); } INTEGRATION OPERATION SEGREGATION PRINCIPLE
  17. 17. OPERATION INTEGRATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); String content = renderMessage(customer, customer.account()); mailService.sendMail(email, content); } private String renderMessage(Customer customer, Account account) { String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; return "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; } INTEGRATION OPERATION SEGREGATION PRINCIPLE
  18. 18. public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); String content = renderMessage(customer, customer.account()); mailService.sendMail(email, content); } private String renderMessage(Customer customer, Account account) { String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; return "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; } TESTS?
  19. 19. OPERATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); String content = renderMessage(customer, customer.account()); mailService.sendMail(email, content); } private String renderMessage(Customer customer, Account account) { String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; return "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; } TESTS? N UNITTESTS
  20. 20. INTEGRATION OPERATION public void sendDiscountMailingTo(String email) { Customer customer = customerDB.findCustomerBy(email); String content = renderMessage(customer, customer.account()); mailService.sendMail(email, content); } private String renderMessage(Customer customer, Account account) { String discount = account == FREE ? "no" : account == BASE ? "a 10%" : account == PREMIUM ? "a 25%" : "-ERROR-"; return "Hello " + customer.getName() + ",nn" + "This week you get " + discount + " discount " + "on all our products.nn" + "Best Regards,n" + "ACME Customer Service"; } TESTS?1 INTEGRATION TEST (or MOCKING TEST) N UNITTESTS
  21. 21. GREEN BAR PATTERNS* Obvious Implementation Fake it (until you make it) Triangulation * Kent Beck in "TDD by Example"
  22. 22. GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation Trade-Off Complexity
  23. 23. GREEN BAR PATTERNS DEMO
  24. 24. SWEET SPOT Trivial GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  25. 25. SWEET SPOT Trivial Structure GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  26. 26. SWEET SPOT Trivial Structure Logic GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  27. 27. PREPARATORY REFACTORINGS* *"An example of preparatory refactoring", Martin Fowler
  28. 28. PREPARATORY REFACTORINGS* *"An example of preparatory refactoring", Martin Fowler
  29. 29. "GREEN" PHASE TRIANGULATION Implementation Run Test "Green Phase"
  30. 30. LIMIT YOUR TIME IN RED "Green Phase" Implementation Run Test
  31. 31. LIMIT YOUR TIME IN RED "Green Phase" Implementation Run Test Implementation Run TestPreparatory Refactoring
  32. 32. PREPARATORY REFACTORINGS DEMO
  33. 33. CALCULATE BACKWARDS DEMO
  34. 34. Acceptance Test UI Persistence OUTSIDE-IN
  35. 35. Acceptance Test UI Persistence OUTSIDE-IN & MOCKS
  36. 36. Unit test Mock OUTSIDE-IN & MOCKS
  37. 37. Unit Test OUTSIDE-IN & MOCKS
  38. 38. Acceptance Test UI Persistence OUTSIDE-IN & MOCKS
  39. 39. Non trivial Acceptance Test OUTSIDE-IN & FAKE IT
  40. 40. Acceptance Test Faked Result OUTSIDE-IN & FAKE IT
  41. 41. Acceptance Test Fake Fake OUTSIDE-IN & FAKE IT
  42. 42. Acceptance Test Drive Structure through Refactoring OUTSIDE-IN & FAKE IT
  43. 43. OUTSIDE-IN & FAKE IT Acceptance Test Unit Test Fill logic with triangulation
  44. 44. OUTSIDE-IN & FAKE IT Acceptance Test Unit Test
  45. 45. OUTSIDE-IN & FAKE IT INTEGRATION Fake It Triangulation OPERATION Start with • comprehensive 
 Acceptance Test • faked result Drive structure by refactoring Drive logic by unit tests
  46. 46. OUTSIDE-IN & FAKE IT INTEGRATION Fake It Triangulation OPERATION Start with • comprehensive 
 Acceptance Test • faked result Drive structure by refactoring Drive logic by unit tests
  47. 47. DIAMOND KATA
  48. 48. FAKE IT OUTSIDE-IN DEMO
  49. 49. MOB PROGRAMMING
  50. 50. DIAMOND KATA
  51. 51. MOB SESSION KATA Continue Diamond Kata ("Upper Left Corner“) Fake it Outside-In constraint https://github.com/davidvoelkel/diamond-kata
  52. 52. RETROSPECTIVE Observations?
  53. 53. RETROSPECTIVE Observations? Strenghts / Weaknesses?
  54. 54. TRADE-OFFS FAKE IT VS OUTSIDE-IN & MOCKS TRIANGULATION
  55. 55. CONDITIONAL INTERACTIONS Mocking when IOSP not possible public String signup(String username) throws Exception { if(userDB.findUserBy(username) == null) { userDB.createUser(new User(username)); return "Welcome " + username; } else { return "Username ' " + username + "' " + "already taken, please choose another"; } }
  56. 56. COUPLING OUTSIDE-IN Mocking Fake It Decoupling Refactorability
  57. 57. DATA GUIDES STRUCTURE Triangulation Fake It Structure Cumbersome Data guides well
  58. 58. # BRANCHES Triangulation Fake It # N 1 More confidence More effort
  59. 59. # BRANCHES Triangulation Fake It # N 1 Fake data easy to forget Omitting cases is tempting
  60. 60. TIME IN GREEN Triangulation Prep Refactoring Triangulation Fake It
  61. 61. WHY? Outside-In => YAGNI free design Without mocking drawbacks
  62. 62. WHY? Outside-In => YAGNI free design Without mocking drawbacks Vs Triangulation More time in GREEN Better Design Guidance
  63. 63. THANKS
  64. 64. LICENSE Creative Commons Attribution-ShareAlike 3.0
  65. 65. IMAGES Most are Public Domain except theses Creative Commons with attributions: "Unstruttalbrücke" by Störfix From State Library of Queensland

×