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 @XP2017

844 views

Published on

These are the slides of my "Fake it Outside-In TDD" session at the #XP2017 conference. 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 @XP2017

  1. 1. FAKE IT OUTSIDE-IN TDD David Völkel 24th May @ XP 2017
  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. 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 2016 SoCraTes DE Outside-In Fake It Session
  7. 7. 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 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement / Work in Progress
  8. 8. INFLUENCES 2003 Kent Beck’s "Fake It" Pattern 2009 #GOOS’s "Outside-In" Design 2013 Emily Bache 
 "Outside-In development with Double Loop TDD" COMBINATION 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement / Work in Progress
  9. 9. 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 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement / Work in Progress
  10. 10. 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“ COMBINATION 2016 SoCraTes DE Outside-In Fake It Session 2017 Refinement / Work in Progress
  11. 11. AGENDA Theory Building Blocks Fake It Outside-In Practice Mob Programming Session Reflect Trade-Offs Discussion
  12. 12. BUILDING BLOCKS
  13. 13. INTEGRATION OPERATION SEGREGATION PRINCIPLE *"Integration Operation Segregation Principle", Ralf Westphal "Die kniffligen Fälle beim Testen - Sichtbarkeit", Stefan Lieser *
  14. 14. 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); }
  15. 15. 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. 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
  18. 18. 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
  19. 19. 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?
  20. 20. 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
  21. 21. 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 N UNITTESTS
  22. 22. GREEN BAR PATTERNS* Obvious Implementation Fake it (until you make it) Triangulation * Kent Beck in "TDD by Example"
  23. 23. GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation Trade-Off Complexity
  24. 24. GREEN BAR PATTERNS DEMO
  25. 25. SWEET SPOT Logic GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  26. 26. SWEET SPOT Structure Logic GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  27. 27. SWEET SPOT Trivial Structure Logic GREEN BAR PATTERNS Obvious Implementation Fake it Triangulation
  28. 28. INTEGRATION OPERATION Fake it Triangulation GREEN BAR PATTERNS Structure Logic IOSP
  29. 29. PREPARATORY REFACTORINGS* *"An example of preparatory refactoring", Martin Fowler
  30. 30. "GREEN" PHASE TRIANGULATION Implementation Run Test "Green Phase"
  31. 31. LIMIT YOUR TIME IN RED "Green Phase" Implementation Run Test Implementation Run TestPreparatory Refactoring
  32. 32. PREPARATORY REFACTORINGS DEMO
  33. 33. Acceptance Test UI Persistence OUTSIDE-IN
  34. 34. Unit test Mock OUTSIDE-IN & MOCKS
  35. 35. Unit Test OUTSIDE-IN & MOCKS
  36. 36. Acceptance Test UI Persistence OUTSIDE-IN & MOCKS
  37. 37. Comprehensive Acceptance Test OUTSIDE-IN & FAKE IT
  38. 38. Comprehensive Acceptance Test Faked Result OUTSIDE-IN & FAKE IT
  39. 39. Acceptance Test Fake Fake OUTSIDE-IN & FAKE IT
  40. 40. Acceptance Test Drive Structure through Refactoring OUTSIDE-IN & FAKE IT
  41. 41. OUTSIDE-IN & FAKE IT Acceptance Test Unit Test Fill logic with triangulation
  42. 42. OUTSIDE-IN & FAKE IT Acceptance Test Unit Test
  43. 43. 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
  44. 44. 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
  45. 45. DIAMOND KATA
  46. 46. FAKE IT OUTSIDE-IN DEMO
  47. 47. FAKE-IT VARIANT CALCULATE BACKWARDS DEMO
  48. 48. PRACTICE
  49. 49. CODING SESSION KATA Continue Diamond Kata https://github.com/davidvoelkel/diamond-kata CONSTRAINTS Drive structure by refactoring Drive conditionals by triangulation
  50. 50. TRADE-OFFS FAKE IT VS OUTSIDE-IN & MOCKS TRIANGULATION
  51. 51. 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"; } }
  52. 52. COUPLING OUTSIDE-IN Mocking Fake It Decoupling Refactorability
  53. 53. DATA GUIDES STRUCTURE Triangulation Fake It Structure Cumbersome Data guides well
  54. 54. # BRANCHES Triangulation Fake It # N 1 More confidence More effort
  55. 55. # BRANCHES Triangulation Fake It # N 1 Fake data easy to forget Omitting cases is tempting
  56. 56. TIME IN GREEN Triangulation Prep Refactoring Triangulation Fake It
  57. 57. DISCUSSION
  58. 58. LICENSE Creative Commons Attribution-ShareAlike 3.0
  59. 59. IMAGES Most are Public Domain except theses Creative Commons with attributions: "Unstruttalbrücke" by Störfix From State Library of Queensland

×