On Feb 22, 5:47 pm, Terry Brown <[email protected]> wrote:
> Writing unit tests to make sure that a bug which was reported in the wild 
> does not recur is useful, but not a great advertisement for unit tests, 
> seeing they didn't prevent the bug hitting the user.  You post wasn't about 
> that, but a lot of the other unit test mentions here are.

To minimize the chance that this happens, having unit tests is not
enough. You must have tests that cover all the code. Unit tests in
combination with code coverage analysis are much more powerful than
unit tests alone. Personally I was pleasantly surprised to learn about
coverage.py and its ability to work as nose plugin. This was a very
considerable addition to my python toolchain. Previous ones were clone
digger, pylint and leo (but of course!).

> I think what holds me back from using unit tests more is the difficulty in 
> writing the tests themselves (not the testing framework).  A lot of code I 
> write has some sort of server / client (web or sql server) aspect which makes 
> constructing a pretend X fiddly.  Not that it can't be done, just that it 
> takes time, and is complex enough to be bug prone itself.  And my work 
> timeframes are not conducive to giving things the time and attention they 
> need.

Tests involving interaction with a web/sql server, any networking I/O
and such, are not unit tests. Period. I was making the same mistake
for quite a few years. The AHA happened when I've read the book
"Working Effectively with Legacy Code" by Michael Feathers. I suggest
you to get that book and read the definition of unit tests: unit tests
are small, they test small code snippets and they complete quickly. If
this is not true - you can't call them unit tests.

>   You should break the problem down into smaller pieces and if you understood 
> it properly it would be easier to write unit tests and they'd be valuable.
> This is probably true.

This is similar to what I've just said above, so you are on the right
path.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to