The principles of test-driven development
Testing is one of the most important elements of the software development process. It is so important that there is even a software development methodology called Test-Driven Development (TDD). It advocates writing software requirements as tests as the first (and foremost) step in developing code.
The principle is simple: you focus on the tests first. Use them to describe the behavior of the software, verify it, and check for potential errors. Only when those tests are complete should you proceed with the actual implementation to satisfy the tests.
TDD, in its simplest form, is an iterative process that consists of the following steps:
- Write tests: Tests should reflect the specification of a functionality or improvement that has not been implemented yet.
- Run tests: At this stage all new tests should fail as the feature or improvement is not yet implemented.
- Write a minimal valid implementation: The code should...