Test clarification
Robey Pointer
robey at lag.net
Thu Dec 1 23:24:33 GMT 2005
On 1 Dec 2005, at 13:32, Robert Collins wrote:
> On Thu, 2005-12-01 at 08:10 -0600, John A Meinel wrote:
>> I just wanted to try and get a consistent use of:
>>
>> self.assertEquals(a, b)
>>
>> Should a or b be the "expected" value.
>>
>> For example, should the test be written:
>>
>> a = somecommand()
>> self.assertEquals(a, 'this text')
>>
>> or
>>
>> a = somecommand()
>> self.assertEquals('this text', a)
>>
>>
>> The former makes a little bit more sense in a "assert a equals b".
>> Which
>> has the feeling that a should be the one doing the equaling.
>>
>> It would be nice if tests were consistent about it, though. So
>> when you
>> look at the errors, you know which one is incorrect.
>
> I tend to use (expected, actual). If we have a standard, it would be
> nice to use that ;).
Probably because that's how all the other *unit libraries implement
it. But to my surprise, python uses the parameters backwards:
>>> import unittest
>>> class C (unittest.TestCase):
... def test_1(self):
... self.assertEquals('1st', '2nd')
...
>>> s = unittest.makeSuite(C)
>>> unittest.TextTestRunner().run(s)
F
======================================================================
FAIL: test_1 (__main__.C)
----------------------------------------------------------------------
Traceback (most recent call last):
File "<stdin>", line 3, in test_1
AssertionError: '1st' != '2nd'
----------------------------------------------------------------------
The python ordering is the most "intuitive" to me, but I'm surprised
they reversed the order from cppunit & junit. That's just going to
be a constant source of confusion. Oh well. :)
robey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051201/a26f3ebb/attachment.pgp
More information about the bazaar
mailing list