Unit Testing With Doubles and Fixtures
In his book Working Effectively with Legacy Code, Michael Feathers defines legacy code as:
“Legacy code is code without tests”
What I like about this sentence is that it illustrates the importance of tests in software development.
There are different ways to view tests. In most cases, tests act as a safety net, helping engineers to catch unwanted changes in the code. However, tests can be much more than this. They can be used as a framework for writing better software, helping engineers to design better APIs and even be used as documentation to help newcomers understand the expected behavior and design decisions.
When writing tests, engineers may use different strategies. Some prefer to write them after the implementation is complete, while others prefer to write them before, such as in test-driven development (TDD) or behavior-driven development (BDD). However, the truth is that these different approaches do not diminish the importance of having good test coverage and testable code.