Why Testing?

Learn about the importance of testing.

We'll cover the following

In this lesson, we will discuss the importance of testing.

Reasons

The main reasons for testing are:

  • To ensure that the code does what we expect now and when we refactor/modify it. Testing protects us from direct regressions when we break the existing code and from indirect regressions when something external from our code breaks it.

  • To reproduce edge cases in the easiest possible way.

  • To leverage the speed of an automated tool that performs checks much faster than you could do manually.

  • To leverage the checks forever, even when it becomes impossible to test everything manually.

  • To tell a story about the code. It’s easier to maintain test descriptions than documentation. A good storytelling test suite allows everyone to jump into the codebase easily.

  • To avoid adding temporary and risky code, conditions, default state, etc. by enabling you to test something.

  • To prevent problems rather than needing to solve them later on.

  • To allow ourselves to refactor the code without fear of ruining the codebase. A well-tested codebase can be refactored safely.

  • To improve the quality of the code: a hard-to-test code is indicative of poor design.

  • To lower your cognitive load. Testing helps you concentrate on your project instead of focusing on everything surrounding it.

  • To have an objective metric that measures the behavioral correctness of your software.

Illustration

Get hands-on with 1200+ tech skills courses.