Why do developers write tests?
Options
- To check the code works as expected, early on (Correct option)
- To make the program run faster in production
- Because every compiler requires them to build
- To increase the total file size of the program
Answer
To check that the code behaves as expected and to catch problems early, especially when the code changes later
Why
Without tests, every change might silently break something else and you only find out when users complain.
With tests, you run a command and see in seconds whether the important behavior still works.
Tests also act as living documentation of how the code should behave.
Remember
Tests = a safety net for changes.