Test Driven Development Overview
Test Driven Development is an important concept within the Agile Development methodology. The Test Driven Development methodology dictates that code be written to test the requirements set forth by the customer before the actual code to implement the requirements is written. In other words, the customer asks for feature A, we write code to test that Feature A works as requested. Once we understand exactly what is required for feature A and what the customers’ acceptance criteria is for Feature A we can then begin to code Feature A.
Test Driven Development Rhythm
Test driven development relies on a repetitive process known as the Test Driven Development Rhythm or TDD Rhythm. The TDD Rhythm states that first a failing test must be written, then just enough code to pass the test should be written finally the code should be refactored as needed for performance and maintainability.
- Write a failing test
- Write just enough code to pass the test
- Refactor for performance and maintainability
Below is an illustration of the expanded TDD rhythm:
Benefits of TDD
The fact that the TDD Rhythm requires that tests exist before any new code is written or changes are made means that if a code is changed and a test doesn’t pass something has been broken. This means we can make changes with the confidence that if the tests pass our update was successful and did not introduce any new bugs.
In order to be able to write a failing test and actually run it and see it fail we need to be able to compile the test project. The only way we can successfully compile and run our test projects is if we have at least enough project structure for our test project and the project that it references to compile. In other words, if we have a Stack Test project that is going to test a project called Stack at a minimum the Stack project must exist.