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.

Mads Opheim

January 31, 2019
Tweet

More Decks by Mads Opheim

Other Decks in Technology

Transcript

  1. Make your tests tell the
    story of your domain
    Anne Landro
    @AnneLandro
    Mads Opheim
    @MadsOpheim
    DDD Europe

    View Slide

  2. Did you know
    that a property
    can own itself?
    2

    View Slide

  3. A project named
    Lovisa
    3

    View Slide

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

    View Slide

  5. We don’t like testing
    5

    View Slide

  6. We don’t like testing
    manual verification
    6

    View Slide

  7. Use your computer
    7

    View Slide

  8. Don’t
    Repeat
    Yourself
    8

    View Slide

  9. Why do we write tests?
    9

    View Slide

  10. Not all tests are
    created equal!
    10

    View Slide

  11. What story do you
    want to tell?
    11

    View Slide

  12. Tell the whole story
    12

    View Slide

  13. What happens when
    you die?
    13

    View Slide

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

    View Slide

  15. One test, several wins
    15

    View Slide

  16. But that’s not all
    16

    View Slide

  17. Value chain your
    unhappy paths
    17

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  21. This one took
    down the
    system
    21

    View Slide

  22. 22
    Test Obscure Scenario That Happens In Production
    Where A Property Owns Itself()

    View Slide

  23. 23
    Test Specific Case In Oslo Where The Property Has No
    Owners()

    View Slide

  24. What is a domain?
    24

    View Slide

  25. What is the technical
    domain?
    25

    View Slide

  26. Different domains,
    different languages
    26

    View Slide

  27. 27

    View Slide

  28. Tell the technical
    details
    28

    View Slide

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

    View Slide

  30. 30

    View Slide

  31. Tell the business
    details
    31

    View Slide

  32. 32
    Contact Every Part In The Claim But Not The Ones Who
    Sent It in()

    View Slide

  33. Tests are as important
    as production code
    33

    View Slide

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

    View Slide

  35. Tests are a swiss army knife
    35

    View Slide

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

    View Slide

  37. Naming tests
    37

    View Slide

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

    View Slide

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

    View Slide

  40. 40
    Properties For Namsmann
    Mainly Follow The Same
    Rules as Hovedstevnevitne()

    View Slide

  41. Don’t tell lies
    41

    View Slide

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

    View Slide

  43. Use real mocks
    43

    View Slide

  44. 44

    View Slide

  45. 45

    View Slide

  46. Beware the copy-paste
    fallacy
    46

    View Slide

  47. Typing prevents
    domain lies
    47

    View Slide

  48. Mob testing
    48

    View Slide

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

    View Slide

  50. Long story short
    50

    View Slide

  51. 51
    The property
    that owns itself

    View Slide

  52. Dank je!
    @MadsOpheim
    [email protected]
    @AnneLandro
    [email protected]
    52

    View Slide