[Python-Dev] unittest's redundant assertions: asserts vs. failIf/Unlesses
Steven D'Aprano
steve at pearwood.info
Sun Jul 13 17:34:53 CEST 2008
On Mon, 14 Jul 2008 12:45:58 am Michael Foord wrote:
> I tend to think of testing as action followed by assertion -
> I do this and this should have happened. Your tests usually define
> 'expected behaviour' rather than defining how your code won't fail...
Who is the "your" that you are speaking for there? It isn't me.
I tend to think of tests as *both* expected behaviour and unexpected
behaviour: sometimes a test is most naturally written as "this should
happen" and sometimes as "this shouldn't happen". It depends on what
I'm testing.
When it comes to test-driven development, I will often start by
thinking "What test can I write to make this code fail?" -- not "what
test can I write to make this code pass?". Having come up with a
failure mode, the test is often most naturally written as "fail if"
or "fail unless", and I resent having to turn the condition around into
a "assert if not" test just to satisfy others who are never going to
read my code. I wish people would go find another bike shed to
interfere with.
--
Steven
More information about the Python-Dev
mailing list