Let's say I'm developing a method where I can pass in two numbers and get the highest number back. Since I'm doing this TDD-style, I will have a dozen unit tests and come up with the following implementation:
public int GetHighestNumber(int x, int y)
{
if (x > y) return x;
else return y;
}
This works extremely well.
The tests have been used to create the implementation. When the implementation has been finished, what is the point in keeping these unit tests? It's like keeping the scaffolding around the house after the house has already been delivered.
I'm not looking for reasons to have unit tests, or if/when to use TDD. I'm just curious about why unit tests should be kept after the code has been fully implemented, instead of having these tests as a temporary means and removed when it doesn't need to support the developer.
Edit
After commenting on CodeGnome I realized I should emphasize that this is just about the TDD-tests, which are created mainly to point the developer in the right direction. The scaffolding so to speak.
I do appreciate all the comments though.
After reading all the messages, I can conclude two things:
Real life code is almost never "finished".
Requirements change and expand. Features are added. Despite TDD, there are bugs to be fixed.
Unit tests also work as regression tests, to prove that the code still works after these changes. This is in fact the most valuable aspect of unit tests (any TDD proponent who claims that it's less important that the design benefits is deluding themselves).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With