[Tutor] another unit-testing question: regex testing

Kent Johnson kent37 at tds.net
Wed Dec 16 02:54:52 CET 2009


On Tue, Dec 15, 2009 at 8:05 PM, Serdar Tumgoren <zstumgoren at gmail.com> wrote:
> I usually build a custom
>> failure message and use the assertXxx() method that takes a message
>> parameter. (In your case, you will have to use a try / catch with a
>> fail() in the try block because assertRaises() doesn't take a msg
>> parameter.)
>
> Not sure I follow here. The try/catch should go in the unit test or
> the code under test?

In the unit test. Instead of
      for id in ids:
           self.assertRaises(models.IDError, models.Office, id)

use something like this:
      for id in ids:
        try:
            models.Office(id)
            self.fail('No exception for ' + id)
        except models.IDError:
            pass

>
> And finally, I was also wondering about testing classes and
> subclasses. For instance, if I have an Office class and a subclass
> Member, can I perform tests on any shared code (i.e. inherited by
> Member) solely against the superclass? Are there any specific types of
> tests that are standard for testing proper inheritance and other such
> issues?

I can't think of specific issues with testing derived classes. I would
test the base class methods in the base class tests. Generally you
just have to test what is added. I think it is similar to building a
function that depends on other functions. The idea is to test
something well, so you believe that it works, then you don't have to
test it anywhere else, you can rely on it.

Kent


More information about the Tutor mailing list