1.

What Does Tdd Give Us That We Can’t Get By Building Tests “after The Fact”?

Answer»

I can think of five main advantages to doing test-driven development over “test-later”. Please let me know if you come up with others:

To make sure the tests get done – It is very EASY to forget important business rules when building tests after the code has been written. TDD helps to guarantee that all of the important features have valid tests written for them.

To help define the problem before solving it – Stopping before building and defining the problem in terms of a test is very helpful for gaining insight into the problem. Often, I have eliminated what would have likely been some significant rework by building my tests first.

To force “design for testability” – ONE of the worst things about writing tests is having to go back and change working code because it isn’t testable. By doing the tests up-front, we guarantee that our code is testable before we EVEN write it. In addition, since testable code is generally decoupled code, TDD helps to enforce a good standard that also helps reduce TCO.

To help validate your tests – When you FOLLOW the results of tests through from throwing a NotImplementedException to returning invalid results, to returning correct results, you have the most confidence that your test is doing what it is supposed to do.

To help prevent SCOPE creep – It is often easy to creep the scope of a development effort by including features that are not currently required, because they seem easy when doing the development. If, however, you require yourself to build tests for each feature first, you are more likely to reconsider adding features that are not currently necessary.

I can think of five main advantages to doing test-driven development over “test-later”. Please let me know if you come up with others:

To make sure the tests get done – It is very easy to forget important business rules when building tests after the code has been written. TDD helps to guarantee that all of the important features have valid tests written for them.

To help define the problem before solving it – Stopping before building and defining the problem in terms of a test is very helpful for gaining insight into the problem. Often, I have eliminated what would have likely been some significant rework by building my tests first.

To force “design for testability” – One of the worst things about writing tests is having to go back and change working code because it isn’t testable. By doing the tests up-front, we guarantee that our code is testable before we even write it. In addition, since testable code is generally decoupled code, TDD helps to enforce a good standard that also helps reduce TCO.

To help validate your tests – When you follow the results of tests through from throwing a NotImplementedException to returning invalid results, to returning correct results, you have the most confidence that your test is doing what it is supposed to do.

To help prevent scope creep – It is often easy to creep the scope of a development effort by including features that are not currently required, because they seem easy when doing the development. If, however, you require yourself to build tests for each feature first, you are more likely to reconsider adding features that are not currently necessary.



Discussion

No Comment Found