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

The Art of Unit Testing

The Art of Unit Testing

Dicoding Indonesia

March 18, 2023
Tweet

More Decks by Dicoding Indonesia

Other Decks in Programming

Transcript

  1. The Art of Unit Testing
    Jessica Cecilia Budianto | Software Engineer - Web Platform

    View Slide

  2. Agenda
    ● Definition
    ● Principles
    ● Structure
    ● Preferences
    ● Practice

    View Slide

  3. Definition

    View Slide

  4. The benefits
    ● Helps to detect potential bug in code
    ● Reflects current code quality
    ● Made sure the code still works properly after refactor / major changes
    ● Documents the features and user flows of our code
    ● Trains our mindset to be a better software developer
    ○ How user interacts with our code
    ○ How edge cases and error might arise from our logic
    ○ Improves attention to detail

    View Slide

  5. Principles

    View Slide

  6. Fast
    It shouldn’t take long 🤔

    View Slide

  7. Isolated / Independent
    Not depending on other test cases

    View Slide

  8. Repeatable
    Not relying on e.g: network
    connection

    View Slide

  9. Self Validating
    A test should immediately
    acknowledges whether it succeeds

    View Slide

  10. Timely
    A test should be able to be written
    before development even started

    View Slide

  11. Understandable
    A test should be like telling a story

    View Slide

  12. Stucture

    View Slide

  13. General Test Structure

    View Slide

  14. Preferences

    View Slide

  15. Top down vs Bottom up

    View Slide

  16. https://kentcdodds.com/blog/write-tests

    View Slide

  17. Test Driven Development (TDD)

    View Slide

  18. But the downsides…
    ● Too focused on testing and making it passed
    ● Time consuming
    ● Harder for big codebase
    ● Even harder if it’s legacy code
    ● Might write a wrong test or miss the edge cases instead

    View Slide

  19. Behavior Driven Development (BDD)

    View Slide

  20. Practice

    View Slide

  21. Github:
    https://github.com/jessicacb12/
    basic-calculator
    Vercel:
    https://basic-calculator-psi.vercel.app/

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. Unit Testing will not just affect your code
    quality, but also your collaboration with
    stakeholders

    View Slide