2021.05.19 Why Write Automated Tests? - GlenKPeterson/One-off_Examples GitHub Wiki

  • Automated tests keep you focused on what the code is supposed to do (rather than how it does it). I often find code usability issues and/or design flaws when writing tests. Writing code with a, "How do I test this?" mindset often leads to better code. (Thanks Jonathan Demirgian).
  • Write tests before refactoring to ensure you preserve old functionality.
  • Reproduce a bug, write a test, fix the bug, know that bug won't happen in production again.
  • Manual regression testing is time consuming and difficult. Having a good suite of automated tests lets you make smaller releases more often with fewer bugs.

See also: https://www.martinfowler.com/testing/

What makes a good test?

  • You don't have to rewrite the entire test any time you touch the code being tested.
  • It's easy to figure out why a test failed.