5 ms·
> testing feels "expensive" to me This is actually one of the bigger 'problems' with {T,B}DD; it's much harder to figure out how much time it takes to complete
by steveklabnik 16y ago
> testing feels "expensive" to me
This is actually one of the bigger 'problems' with {T,B}DD; it's much harder to figure out how much time it takes to complete things.
BDD: Wrote the test, wrote the feature, checked it in, wall clock time, 1 hour. Next week, something unrelated changes, my tests show right where the problem is, 10 minute fix. Total time: 1:10.
No testing: wrote the feature, half an hour. Next week, something unrelated changes, breaks the feature, spend an hour fixing it. Total time: 1:30. And keep adding time when other things break later, too...
In projects with a high test coverage, I almost never spend any time debugging. That doesn't mean it's easy to recognize the saved time, though.
- nickelplate 16y agoWhat about POUT (plain old unit testing)? Ie writing he test after the feature?
- steveklabnik 16y agoThis might be my own personal failing, but those tests will never get written. Once the feature works, the temptation to move onto the next thing is just too great. Also, by writing the test first, you ensure that the code is actually easy to test. This gets easier as you get more experienced with testing, but still.
- demallien 16y agoAlso, writing the test first helps in identifying a sane API, I personally consider this to be the single greatest advantage of TDD. I don't write as many tests as you do though, Steve. I generally stop once I have the nominal test cases in place, I don't test edge cases. They seem to tend to get hit by upstream unit tests anyway (I don't mock except where it is absolutely necessary). If I do hit a difficult-to-find bug, I use tests as one of my main debugging tools, writing tests for any code for which I have some doubts. By the end of a project, I generally have a fairly high code coverage for my tests, but I never feel like I'm just writing them for the methodology - they are either testing the nominal case, or testing to verify behaviour when tracking down a bug
- steveklabnik 16y ago> helps in identifying a sane API I totally forgot about this, but I agree 100%. I'm a big fan of "Write this as though the underlying code exists, then fill it out" for API design. I don't write as many tests as you'd think I do, actually, because I heavily favor integration tests over unit-style tests, and so we're probably much closer in that regard than you think. ;)
- jsdalton 16y agoI think the difficulties I've personally had with embracing TDD come down to a slightly different set of experiences: TDD: Spend an hour writing the test (sometimes more if I have to figure out how to properly work with a third-party library). Spend 10 minutes writing the code. Decide a few days later that I need to rework the API a bit on the feature, so spend another hour rewriting tests and 5 minutes writing new production code. No testing: Write the feature, 20 minutes. "Test" while writing it (refresh a web page or run something at the CL). Realize a few days later I need to rework things, spend 10 minutes doing so. In the rare instances where something breaks, spend 20 or 30 minutes tracking it down and fixing. Don't read this as an argument against TDD. It's more that I have a very hard time actually realizing an increase in productivity or code quality when using it. TDD-backed code generally takes me longer to write and pretty much nobody on the business team I report to notices any difference whatsoever, except that feature X took a week longer than it probably would have otherwise. The few bugs that do creep into production code are usually dealt with promptly, and I'm not sure TDD would result in entirely bug-free code either way. Anyhow, that's why this conversation has been quite valuable to me. I am convinced that if I can clear away real-world obstacles in TDD I can do a better job of embracing it and realizing the productivity benefits that everyone always crows about. For now, my personal experience is that it's a means to marginally improve code quality at a high cost of time.
- alexro 16y ago> nobody on the business team I report to notices any difference whatsoever, except that feature X took a week longer than it probably would have otherwise This. And also Refactoring is almost a dirty word so we try to keep it to ourselves and sneak in bits of refactoring when implementing bigger features
- steveklabnik 16y agoTesting is a skill like any other. When you started programming, I'm sure you were quite slow at it, as well. As you level up your testing skill, the time it takes to write tests drops down. At first, it's really slow going, though, I agree. I also have the pleasure of writing 90% of my code in Ruby, which has top notch testing support basically everywhere.
- 16y ago