Code correctness, and testing strategies

Scott David Daniels Scott.Daniels at Acm.Org
Sun May 25 18:31:29 EDT 2008


David wrote:

> It was an interesting exercise, and I'm encouraged to try it further.
Yes, The developed code is missing an overview, but this is an example 
implementing something we all understand a "stack".  The layout is a
little short on vertical whitespace, but I'm presuming you do that for
e-mail / newsgroup purposes.

> Would you normally start with a basic TestStackBehavoiur class, and
> when Stack becomes more complicated, split the tests up into
> TestEmptyStackContext, TestStackWithOneElementContext, etc?
I split about the time my setUp or tearDown needs to get tricky in order
to handle my different cases.  I also often add new classes for new 
projects.

> Another thing I noticed is that some of my test cases were redundant.
> Would you normally leave in the redundant tests, or remove the ones
> which are included in the more general test?
I get a bit lazy about refactoring tests.

> Also, I have another question. How do you unit test event loops?
I seldom do event loop _unit_ tests.  Most of the code is not in the
event environment, so most of the code I unit test is broken out.
If you have to be a bit more in bed with the event system, consider
a mock event system that connects to your code and provides specific
event chains and "expects" certain responses.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list