[Tutor] Do you use unit testing?
denis.spir at free.fr
Tue Nov 17 09:15:08 CET 2009
Le Mon, 16 Nov 2009 13:54:26 -0700,
Modulok <modulok at gmail.com> stated:
> A general question:
> How many of you guys use unit testing as a development model, or at
> all for that matter?
I do. Systematically. Has become a reflex.
I would rather ask the opposite question: how do know a part of your code actually works if you don't test it?
What I do not do is writing the tests before developping. Probably because my style of programming is rather "exploratory", or incremental: I discover and expand while developping, so that I cannot predict what a relevant test may be. Test-driven development relies on full, accurate, detailed specification even before design; actually pre-development test code forms a kind of specif.
> I just starting messing around with it and it seems painfully slow to
> have to write a test for everything you do. Thoughts, experiences,
> pros, cons?
Yes, you're right: "it seems painfully slow". It's an illusion. Just like the illusion that writing "user_account" rather than "usr_acnt" will slow your development pace. (I read once that developpers spend less than 1% of their time actually typing.) There's something wrong in humain brains ;-)
Writing a test func for a bit of code lets you:
* understand your code better
* find flaws and bugs before even testing
* find remaining flaws and bugs (but not all)
* validate your code (mentally, if only for yourself)
* validate changes (possibly in other code parts, related to this one)
It's much faster and better than letting unfinished code with "bombs" everywhere, that will randomly explode. Especially because numerous bugs won't look like beeing related to their actual source.
> Just looking for input and different angles on the matter, from the
> Python community.
Good question, imo!
* la vita e estrany *
More information about the Tutor