isA function?

Delaney, Timothy tdelaney at avaya.com
Mon Jul 15 00:29:06 EDT 2002


> From: Peter Hansen [mailto:peter at engcorp.com]
> 
> For example, a unit test for a factory function might be checking
> that instances of several different classes were being returned
> depending on the parameters passed in.
> 
> If the code were broken so that only a single class was represented
> in the returned objects, Timothy's test would continue to pass
> (bad!) while yours would fail - just as you'd want - alerting you
> to the bug.

Why would this be bad? Presumably you are testing that the returned objects
have specified semantics. What does it matter if the returned objects are
all of the same type or not - what is important is what happens when you use
them.

Assuming that the code was *broken*, this would show up in other tests.

Artificially restricting the types that you can deal with is generally a bad
idea. If it passes all the unit tests, either it is acceptable, or your unit
tests are broken. If it passes all your unit tests except for an arbitrary
type check, then I contend that your unit test is broken.

Tim Delaney





More information about the Python-list mailing list