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

Writing testable code

Writing testable code

B5dce3bdf38e652f73ee65ffe25d7931?s=128

Rodrigo Boniatti

November 30, 2019
Tweet

More Decks by Rodrigo Boniatti

Other Decks in Programming

Transcript

  1. Writing testable code

  2. Rodrigo Boniatti Developer at Codeminer 42 @boniattirodrigo rodrigoboniatti.com

  3. Conditionals

  4. None
  5. Smell

  6. None
  7. None
  8. Refactored

  9. None
  10. None
  11. Conditionals • Smell: • High cyclomatic complexity score; • How

    to solve? • Replace Conditional with Polymorphism;
  12. Global state

  13. Smell

  14. None
  15. Refactored

  16. None
  17. Global state • Smell: • Coupling; • How to solve?

    • Dependency injection;
  18. Life cycle events

  19. Smell

  20. None
  21. Refactored

  22. None
  23. Life cycle events • Smell: • Hide code behavior; •

    No execution order; • How to solve? • Single flow;
  24. Principles of testing

  25. Principles of testing • Test in isolation; • A lot

    of setup == smell; • Hard to test == smell;
  26. Questions?

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