Unittest - How do I code lots of simple tests
Anthony Briggs
abriggs at westnet.com.au
Wed Oct 22 07:34:45 EDT 2003
At 3:11 AM -0700 10/22/03, Paul Moore wrote:
>Peter Hansen <peter at engcorp.com> wrote in message
>news:<3F95A5DC.51828269 at engcorp.com>...
> > > No, you don't get the psychologically affirming "52 tests passed!"
>> without changes to the TestRunner, but I assume the non-cosmetic part
>> of this is more your concern right now...
>
>I don't see the remainder of the problem as "non-cosmetic". The error
>report I get (or rather the information it offers) is
>
> 1 test failed - pass count is 25 instead of 52.
>
>But that doesn't tell me *which* tests failed.
Are you running the tests verbosely? eg. with a -v argument under
UNIX, or as specified in the docs
<http://www.python.org/doc/current/lib/minimal-example.html>? I get
the following output when using Miki's code (with a deliberate error
thrown in, and the print statement commented out):
bash-2.05b$ ./test.py -v
test_1_I (__main__.KnownValues) ... ok
test_2_II (__main__.KnownValues) ... ok
test_3_II (__main__.KnownValues) ... FAIL
test_4_IV (__main__.KnownValues) ... ok
test_5_V (__main__.KnownValues) ... ok
======================================================================
FAIL: test_3_II (__main__.KnownValues)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./test.py", line 21, in test
self.assertEqual(r, result)
File "/usr/local/lib/python2.3/unittest.py", line 292, in failUnlessEqual
raise self.failureException, \
AssertionError: 'II' != 'III'
----------------------------------------------------------------------
Ran 5 tests in 0.055s
FAILED (failures=1)
bash-2.05b$
>The key point here is that I'm NOT running one test - I really am
>running 52 distinct tests. OK, they are all very similar, differing
>only in the data - but for pity's sake, isn't that what an object
>oriented structure is supposed to make easy???
Well, you're testing one aspect of the code. It's really just a
question of how you think about your tests.
Anthony
--
----------------------------------------------------
HyPEraCtiVE? HeY, WhO aRE YoU cALliNg HypERaCtIve?!
aBRiGgS at wEStNeT.cOm.aU
----------------------------------------------------
More information about the Python-list
mailing list