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

Your tests are mocking you

Jakub Zalas
February 15, 2024
130

Your tests are mocking you

Test doubles (a.k.a. “mocks”) managed to gain a bad reputation over the years for causing unreadable and hard-to-maintain tests. Years of misuse led to some programmers advising against test doubles. Even though they are fundamental in the London school of Test Driven Development.

In this talk, Jakub will go back to the origins of the technique to explain scenarios when it's best used and look at common pitfalls. We’ll discuss various types of test doubles based on examples and show how to make them trustworthy. The key to success, as it turns out, will be a combination of contract (role) and collaboration tests.

Jakub Zalas

February 15, 2024
Tweet

Transcript

  1. * Quick introduction * Behaviour & Veri fi cation *

    The chain premise * Collaboration tests * Contract tests * Mocking hell PLAN
  2. “TEST A CHAIN BY TESTING EACH LINK” MICHAEL "GEEPAW" HILL

    https://www.geepawhill.org/2018/01/16/underplayed-the-chain-premise-in-depth/
  3. WE GET TO CHOOSE WHEN AND WHERE WE BREAK THE

    DEPENDENCY CHAIN FOR TESTING
  4. SPY

  5. THANK YOU Verify behaviour, not implementation Mock roles, not objects

    Listen to your tests, let them guide your design Keep your tests as tidy as the codebase Leverage test doubles as a TDD tool @jakub_zalas @jakub_zalas @jakzal