[Zope3-dev] XP Jargon?

Shane Hathaway shane at zope.com
Thu Jan 29 12:01:18 EST 2004


On Wed, 28 Jan 2004, Casey Duncan wrote:

> Also, what is a unit test depends on your point of view. For instance,
> what is a unit test of my application, is probably a functional test of
> Python if not of the operating system.
> 
> I do find it useful to keep each unit test method as specific as
> possible. Resist the temptation to test multiple behaviors (no matter
> how trivial) in a single unit test method. I'm not sure how this applies
> to doctest, but I'm sure it can.

FWIW, I'm not sure about that, and I'm looking for the right compromise.  
The way I see it, a method of a TestCase subclass might not be a test.  
Instead, it might contain setup code and a series of tests.  The actual
tests are only part of the method.  For example:

    def testLooksLikeADict(self):
	# Set up
        d = self.obj
        d['foo'] = 1
	d['bar'] = 2

	# Tests
	self.assertEqual(d['foo'], 1)
	self.assertEqual(d.get('foo', 1))
	self.assertEqual(d['bar'], 2)
	self.assertEqual(d.get('unlikely key'), None)
	# Many others should follow...

It would be painful to write a method for each of these one-line tests.  
The only disadvantage of doing this, AFAICS, is that the first failure
cancels the rest of the tests in the method.  One way to deal with that
would be to make assertEqual() log the results rather than propagate the
AssertionError immediately.

On a related note, I'm intrigued by Ward Cunningham's ideas.  He has
created a table-based testing framework.  You write a table that specifies
the inputs and the expected outputs, then verify the code does what the
table specified.  It's hard to get any simpler than that.

http://fit.c2.com/wiki.cgi?SimpleExample

Then he goes on to use a similar table as a script for functional testing.

http://fit.c2.com/wiki.cgi?WebPageExample

I think doctest does approximately the same thing as Ward's tables, 
although doctest is bound with Python syntax nuances, while the tables 
seem language-independent.

Shane



More information about the Zope3-dev mailing list