8 ms·
I don't understand where/how in TDD you are allowed to switch from concrete "base case" tests to tests which probe the inductive hypothesis. It seems that TDD
by kazinator 4y ago
I don't understand where/how in TDD you are allowed to switch from concrete "base case" tests to tests which probe the inductive hypothesis.
It seems that TDD can forever evade actually solving a problem in its general form, always just extending the number of concrete cases that work.
For instance, a function to measure the length of a string first works only for the case len("") == 0; the result is wrong for all else. TDD allows this to be extended into "working" in idiotic steps like len("a") == 1, but len("b") returns 0, and so on.
Also, how, in TDD, can we write a test which says "for any input not handled by the tests developed so far, I want an exception". That is to say, when I write the first test len("") == 0 and get it to pass, I don't want len("a") to return 0; I want it to throw. I could write a test for that: throws(len("a")), and it would initially fail. But I want the behavior to be entirely general, and I don't want to maintain the test when len("a") changes to returning 1.
These problems make TDD just look like a way to get useful work out of complete morons, in problem areas involving calculating functions that have finite domains that can be exhaustively tested.
As soon as you write a code that is more general: which makes more than the new test case to pass, you're leaving TDD. For instance, the test case wants len("a") == 1, but you write code such that len("b") == 1 would also pass, and len("abc") == 3 would also pass and so on. You now have a lot of useful and good behavior that is not tested. You've not had a len("abc") == 3 which went from red to green.
Once other code starts relying on len being a reliable length function, you must have left TDD behind. Code is calling len("foo.txt"), which has not been tested! How realistic is to prevent that?
At some point, a supposedly TDD-developed program must handle real-world inputs, and they could not all have been tested, because that's the reality. Only simple functions with small finite input spaces can be exhaustively tested. TDD must necessarily allow a lack of testing to creep in, and the rules for that, if any, are ad hoc.