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

Writing testable code

Writing testable code

Rodrigo Boniatti

November 30, 2019
Tweet

More Decks by Rodrigo Boniatti

Other Decks in Programming

Transcript

  1. Writing testable code

    View full-size slide

  2. Rodrigo Boniatti
    Developer at Codeminer 42

    @boniattirodrigo

    rodrigoboniatti.com

    View full-size slide

  3. Conditionals

    View full-size slide

  4. Conditionals
    • Smell:
    • High cyclomatic complexity score;

    • How to solve?
    • Replace Conditional with Polymorphism;

    View full-size slide

  5. Global state

    View full-size slide

  6. Global state
    • Smell:
    • Coupling;

    • How to solve?
    • Dependency injection;

    View full-size slide

  7. Life cycle events

    View full-size slide

  8. Life cycle events
    • Smell:
    • Hide code behavior;

    • No execution order;

    • How to solve?
    • Single flow;

    View full-size slide

  9. Principles of testing

    View full-size slide

  10. Principles of testing
    • Test in isolation;

    • A lot of setup == smell;

    • Hard to test == smell;

    View full-size slide

  11. Thank you
    Code examples: https://github.com/boniattirodrigo/writing-testable-code

    View full-size slide