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

Test doubles explained in Kotlin

Test doubles explained in Kotlin

Test doubles, also known as “mocks”, managed to gain a reputation for causing unreadable and hard-to-maintain tests. Is the screwdriver to blame for the inability to hammer in the nail?

In this talk, Jakub will go back to the origins of test doubles to explain scenarios when they’re best used. We’ll discuss various types of test doubles based on examples and show how to make them trustworthy. Finally, we’ll explore the possibilities of replacing auto-mocking libraries with hand-crafted test doubles using features of a modern programming language like Kotlin.

Jakub Zalas

July 04, 2024
Tweet

More Decks by Jakub Zalas

Other Decks in Programming

Transcript

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

    The chain premise * Collaboration tests * Contract tests 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. COMMON PITFALLS * Value mocking * Getters mocking * Unnecessary

    mocking * Mock orchestration / mimicking the implementation * Mocking disproportionally more complex than the code * Adding expectations on numbers of calls * Mocking 3rd party code
  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