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

Programowanie wspierane przez testy po londyńsku

Programowanie wspierane przez testy po londyńsku

Jakub Zalas

May 27, 2023
Tweet

More Decks by Jakub Zalas

Other Decks in Technology

Transcript

  1. JAKUB ZALAS
    PO LONDYŃSKU
    PROGRAMOWANIE


    WSPIERANE PRZEZ TESTY
    PHP


    EDITION

    View full-size slide

  2. Jakub Zalas
    @jakub_zalas
    @jakub_zalas
    @jakzal

    View full-size slide

  3. - Behaviour


    - Veri
    fi
    cation


    - The chain premise


    - Collaboration tests


    - Test doubles


    - Contract tests


    - Mocking hell
    PLAN

    View full-size slide

  4. https://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam
    Beware the Integrated Tests Scam
    J. B. Rainsberger / @jbrains

    View full-size slide

  5. DATA
    CALCULATIONS
    ACTIONS
    Grokking Simplicity


    Eric Normand
    2021

    View full-size slide

  6. “TEST A CHAIN BY TESTING EACH LINK”
    MICHAEL "GEEPAW" HILL
    https://www.geepawhill.org/2018/01/16/underplayed-the-chain-premise-in-depth/

    View full-size slide

  7. WE GET TO CHOOSE


    WHEN AND WHERE


    WE BREAK THE DEPENDENCY CHAIN


    FOR TESTING

    View full-size slide

  8. COLLABORATION TESTS

    View full-size slide

  9. INDIRECT INPUT
    INDIRECT OUTPUT

    View full-size slide

  10. xUnit Test Patterns


    Refactoring Test Code
    Gerard Meszaros
    2007


    View full-size slide

  11. WE HAVE DETECTED UNUSUALLY HIGH SPENDING
    ON YOUR CARD IN THESE CATEGORIES:


    • YOU SPENT £101.19 ON FOOD


    • YOU SPENT £27.70 ON ENTERTAINMENT


    https://github.com/testdouble/contributing-tests/wiki/Unusual-Spending-Kata

    View full-size slide

  12. SPY & STUB
    HAND-CRAFTED

    View full-size slide

  13. A REAL OBJECT,


    BUT A DUMMY


    WOULD WORK AS WELL.

    View full-size slide

  14. MOCK OBJECT
    HAND-CRAFTED

    View full-size slide

  15. A MOCK OBJECT

    View full-size slide

  16. A MOCK OBJECT

    View full-size slide

  17. A MOCK OBJECT

    View full-size slide

  18. STUB & MOCK OBJECT
    WITH A MOCKING FRAMEWORK

    View full-size slide

  19. A MOCK OBJECT

    View full-size slide

  20. A MOCK OBJECT

    View full-size slide

  21. CONTRACT TESTS
    aka "Role tests"

    View full-size slide

  22. UnusualSpendingNotificationUseCaseTest

    View full-size slide

  23. UnusualSpendingNotificationUseCaseTest

    View full-size slide

  24. UnusualSpendingQueryTest
    UnusualSpendingQueryTest
    UnusualSpendingNotificationUseCaseTest

    View full-size slide

  25. THANK YOU
    Verify behaviour


    Mock roles, not objects


    Listen to your tests


    Leverage test doubles as a TDD tool
    @jakub_zalas
    @jakub_zalas
    @jakzal

    View full-size slide