Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make your tests tell the story of your domain

Make your tests tell the story of your domain

Even with perfect naming and perfect code, it is hard to read the story of your domain straight out of it. You can be certain that you’ll have forgotten some of the nuances about the code the next time you see it. Or someone else sees it, because very few of us live our professional coding lives in an area where it’s only me ever handling the code. Someone is going to come back to your code - in five days, three months or five years.

Luckily, if you write your tests the right way, they can tell the story of your domain in a way your production code can't. Let us show you how to create your tests so you can get rid of your stale documentation.

Co-presentation with Anne Landro.

52482b46b478633a2b766bbf36916fd3?s=128

Mads Opheim

January 31, 2019
Tweet

Transcript

  1. Make your tests tell the story of your domain Anne

    Landro @AnneLandro Mads Opheim @MadsOpheim DDD Europe
  2. Did you know that a property can own itself? 2

  3. A project named Lovisa 3

  4. A long time ago in a Lovisa far, far away

    4
  5. We don’t like testing 5

  6. We don’t like testing manual verification 6

  7. Use your computer 7

  8. Don’t Repeat Yourself 8

  9. Why do we write tests? 9

  10. Not all tests are created equal! 10

  11. What story do you want to tell? 11

  12. Tell the whole story 12

  13. What happens when you die? 13

  14. 14 PersonIsRegisteredAsDeadAfterStartOfACaseOfDeath: createACaseOfDeath() registerTheDiseased() registerTheHeirs() notifyTheNationalRegistryOfTheDeath() assertThatThePersonIsRegisteredAsDead()

  15. One test, several wins 15

  16. But that’s not all 16

  17. Value chain your unhappy paths 17

  18. 18 courtWillContactYou: writeALetterToSend() sendLetterByMail() receiveAnswer() assertThatYouHaveConfirmedToReceiveTheLetter()

  19. 19 courtWillDoSeveralAttemptsToContactYou: writeALetterToSend() sendLetterByMail() waitTwoWeeksForAnswer() sendThePoliceToYourDoorToGiveYouTheLetterInPerson() assertThatYouHaveConfirmedToReceiveTheLetter()

  20. Tell the quirks of the domain 20 Test rare occurences

  21. This one took down the system 21

  22. 22 Test Obscure Scenario That Happens In Production Where A

    Property Owns Itself()
  23. 23 Test Specific Case In Oslo Where The Property Has

    No Owners()
  24. What is a domain? 24

  25. What is the technical domain? 25

  26. Different domains, different languages 26

  27. 27

  28. Tell the technical details 28

  29. SearchForHouseTest.java RegisterHouseTest.java MatrikkelFacadeTest.java 29

  30. 30

  31. Tell the business details 31

  32. 32 Contact Every Part In The Claim But Not The

    Ones Who Sent It in()
  33. Tests are as important as production code 33

  34. Production code solves problems, test code visualizes them 34

  35. Tests are a swiss army knife 35

  36. Tell the story bearing in mind that you’ll forget things

    36
  37. Naming tests 37

  38. How to know if your test name ain’t good? 38

  39. 39 The Deadline For Kunngjøring Is Four Weeks()

  40. 40 Properties For Namsmann Mainly Follow The Same Rules as

    Hovedstevnevitne()
  41. Don’t tell lies 41

  42. 42 The Deadline For Kunngjøring Is Four Weeks()

  43. Use real mocks 43

  44. 44

  45. 45

  46. Beware the copy-paste fallacy 46

  47. Typing prevents domain lies 47

  48. Mob testing 48

  49. Mob testing – fun for the whole team(?) 49

  50. Long story short 50

  51. 51 The property that owns itself

  52. Dank je! @MadsOpheim mads.opheim@computas.com @AnneLandro anne.landro@computas.com 52