Hi –
On Sun, 3 Aug 2008, James B. wrote:
something running before I can get my brain into test mode. Certainly
with something like Rails, there’s a lot to do before any tests are
written, since you can’t write unit tests before you know what your
models are (and generating the model so conveniently writes the test
file for youIsn’t the idea of TDD and BDD that you discover what classes and method are
needed by writing the tests first? So there should be no model in place
prior to writing the test; the initial failure of the test is what drive the
creation of the model.
That may be the ideal for some people, but not for me when I’m
modeling a domain and especially when I’m working out a database
schema. I don’t consider unit tests to have superseded the other tools
that support those activities, including blank pieces of paper and
index cards and so on. I guess you could write unit tests for a Rails
app before creating the models, if you mocked up the objects’
attributes, their associated objects, and so on (since there would
presumably be no database yet), and then rename your files so they
don’t get clobbered when you generate the test files… but it seems
like it would be terribly arduous, with no real gain, and I don’t
think I’ve ever seen anyone do it.
literally written code test-first from the time they first learned how
to program onward. I suspect the answer is no – and if that’s the
case, it means that there is no evidence for the position that it’s
always, automatically bad to write code without a test.Has anyone ever seen a Learn To Program or Learn Language Blub book that did
TDD? I doubt such a thing exists. Instead, people are shown code,
encouraged to write code, then (in so many words) told that what they were
shown and told is not the right way to code. On the other hand, having a
unit test for the 1-liner helloworld.rb seems massively goofy.
The thing is, all the people who argue that testing first is the right
way to code did not themselves learn to code that way. That doesn’t
prove or disprove anything, but it does make me wonder whether
teaching someone test methodology right out of the starting gate is
demonstrably the best way to go about teaching someone programming. I
tend to think it isn’t, though I also think that there are good and
bad ways to introduce testing into the mix (the best way probably
being to present it as essentially what they’ve been doing all along,
but more structured; and the worst way being the “OK, the fun is over,
now let’s get serious” stuff).
David