Unit testing is the concept of taking a single function or part of our code, and writing assertions and tests to ensure that it works as intended.
Proof of correctness
Without unit tests, there is blind reliance on end-to-end manual tests to ensure that our feature or part of the application actually works. Unit tests act as proof that what we have developed actually does what it is supposed to, that we have handled all the edge cases correctly, and that it delivers the correct result in all these cases.
Lack of compiler
Catch errors early
Without unit tests, we would only know about an error in our application after we hit refresh in our browser and saw the live application. Unit tests can help us catch errors much earlier, reducing turnaround time and thus increasing our development speed.
At the end of the day, we are unlikely to be the only person working on our codebase. Other developers will inevitably rely on or actively change parts of the codebase that we developed. You can ensure that they don’t change any fundamental assumptions by providing a set of unit tests that prevent regressions and bugs in the future.
Comments have a bad habit of becoming outdated. Unit tests in AngularJS, especially written using Jasmine, look and read like English. And because unit tests break when the underlying code changes, we are forced to keep comments updated. So unit tests can act as a living, breathing specification for our codebase.