From the perspective of someone who practices Test-Driven Development, this gets things backwards. I believe that it
From the perspective of
someone who practices Test-Driven Development (TDD)
, this gets things backwards. I believe that it is an essential part of TDD that you must write your unit test before writing any application code. Why does it matter?
Test-Driven Development is first and foremost an application design methodology . If you write your unit tests after you write your application code, then you are not driving the design of your application with your unit tests. In other words, Test-After Development ignores the Driven in Test-Driven Development.
Let’s consider a concrete scenario… Here are the steps that I would follow using Test-Driven Development:
- Write a list of user stories that describe what the application should do. These user stories should be non-technical (the type of thing that a customer would write).
- Pick a user story and express the user story in a unit test.
- Write just enough code to pass the unit test. In other words, do the simplest thing that could possibly work to pass the unit test.
- Consider refactoring my code to improve the design of my application. I can fearlessly refactor because my code is covered by unit tests.
- Repeat steps 2 – 3 until I have completed the application (keeping in mind that the user stories might change over the course of the process of writing the application).
Otherwise, here are the steps that a “Test-After Developer” should do:
- Create a list of user stories.
- Consider the best design for the application (create separate controller and repository classes).
- Write application code that follows the design.
- Write unit tests for the code.
- Repeat steps 2 – 4 until the forums application is completed.
Someone who practices Test-After Development starts by writing application code and then writes a unit test after the application code is written. More to the point, a proponent of Test-After Development makes all of their design decisions up front.
The crucial difference between Test-Driven Development and Test-After Development is a difference in belief about the importance of incremental design. Practitioners of Test-Driven Development take baby steps in improving the design of an application. Practitioners of Test-After Development attempt to implement good design from the very start.
Comments? Contact us for more information. We’ll quickly get back to you with the information you need.