Save 37% off PRO during our Black Friday Sale! »

3 Steps Every Test Should Take

3 Steps Every Test Should Take

37fe41bfaedec54a55f9bbbc67e1f006?s=128

Matheus Richard

May 27, 2021
Tweet

Transcript

  1. 3 Steps Every Test Should Take

  2. About me Matheus Richard

  3. This is a ⚡lightning talk⚡, so I’m gonna go FAST

    󰝊💨
  4. 🧪 Tests

  5. 😄 Tests are good! They make us more productive. Right?

  6. ❌ WRONG!

  7. ✔Good tests are good

  8. 🐢 Poorly written tests slow us down!

  9. Developer happiness-meter: 🙁 🐌 Slow tests

  10. Developer happiness-meter: 😞 🤔 Confusing tests 🐌 Slow tests

  11. 󰣽 Flaky tests Developer happiness-meter: 😠 🤔 Confusing tests 🐌

    Slow tests
  12. 󰣽 Flaky tests Developer happiness-meter: 🤬 🤔 Confusing tests 📦

    Brittle tests 🐌 Slow tests
  13. 🐌 Slow tests 󰣽 Flaky tests 📦 Brittle tests 🤔

    Confusing tests
  14. Good tests tell a story

  15. The story has 4 acts

  16. 📝 1. Setup

  17. 📝 1. Setup Create objects Define function inputs

  18. 📝 1. Setup 🏋 2. Exercise

  19. 📝 1. Setup 🏋 2. Exercise Calling methods Saving objects

    to DB
  20. 📝 1. Setup 🏋 2. Exercise 󰡷 3. Verify

  21. 📝 1. Setup 🏋 2. Exercise 󰡷 3. Verify Check

    if the output is the expected
  22. 📝 1. Setup 󰡷 3. Verify 🏋 2. Exercise 💥

    4. Teardown
  23. 📝 1. Setup 󰡷 3. Verify 🏋 2. Exercise 💥

    4. Teardown Undo changes Release memory Restore DB
  24. 📝 1. Setup 🏋 2. Exercise 󰡷 3. Verify 💥

    4. Teardown You’re welcome!
  25. 📝 1. Setup 󰡷 3. Verify 🏋 2. Exercise

  26. 📝 1. Arrange 󰡷 3. Assert 🏋 2. Act aka

  27. 📝 1. Given 󰡷 3. Then 🏋 2. When aka

  28. None
  29. None
  30. None
  31. 🤨 Why is this good?

  32. Consistency

  33. None
  34. None
  35. None
  36. None
  37. E X E R C I S E

  38. Tests are self-contained. No mystery guests here

  39. None
  40. 1. Verify Developer confusion-meter: 🤔❓

  41. 1. Verify 2. Exercise + Setup Developer confusion-meter: 🥴⁉

  42. 1. Verify 2. Exercise + Setup? 3. Verify Developer confusion-meter:

    😵
  43. Developer confusion-meter: 😵

  44. Developer happiness-meter: 🥰

  45. SPACE IS IMPORTANT Developer happiness-meter: 🥰

  46. Developer happiness-meter: 😐

  47. Developer happiness-meter: 🥰

  48. Good tests have 4 3 steps

  49. 📝 1. Setup

  50. 📝 1. Setup 🏋 2. Exercise

  51. 📝 1. Setup 󰡷 3. Verify 🏋 2. Exercise

  52. We need not only tests, but good tests!

  53. We want good code and tests are code too!

  54. That’s it Feel free to ask any question