Re:Why I don’t use TDD or BDD
by jules on Saturday September 04, 2010 @06:11PM
(#1663507)
It is very much dependent on the kind of code you write. If you write UI code then automated testing might not help you much. But for algorithmic code you can usually write short tests that test very comprehensively and catch nearly all bugs.
For example if you are writing a sorting function you write some code to generate a random array, sort it, and test whether it is sorted.
n = random int;
A = int[n];
for(i in 0..n) A[i] = random int;
sort(A);
for(i in 0..n-1) assert(A[i] <= A[i+1]);
Running this kind of test saves you a heck of a lot of time manually testing scenarios, and it tests much more comprehensively too. Tools like QuickCheck make this style of testing even easier by providing ways to randomly generate things and if it finds a bug it tries to get a small example that produces buggy behavior.
I do not see much value in the kind of testing a lot of people seem to do though, for example in a web application putting something in the database and then testing that it's there. If the test is about as complicated or more complicated than the thing it's testing that is a good sign the test is not very useful.
For example if you are writing a sorting function you write some code to generate a random array, sort it, and test whether it is sorted.
Running this kind of test saves you a heck of a lot of time manually testing scenarios, and it tests much more comprehensively too. Tools like QuickCheck make this style of testing even easier by providing ways to randomly generate things and if it finds a bug it tries to get a small example that produces buggy behavior.I do not see much value in the kind of testing a lot of people seem to do though, for example in a web application putting something in the database and then testing that it's there. If the test is about as complicated or more complicated than the thing it's testing that is a good sign the test is not very useful.