Martin Pool's blog

py.test

Ian Bicking writes of py.test, a Python testing framework.

It is, to be sure, a big improvement on the standard unittest module, which has far strong of a Java flavor to be comfortable in Python. It is similar to my comfychair in some ways, and probably superior at the moment (though there are some comfychair features I am quite fond of.)

I think the problem with unittest (and to a much lesser extent the current version of comfychair) can be seen by considering a definition of a class: a class is a set of objects with different data sharing common behavior.

That implies one should create a class when there is particular behavior, and when that behavior is common to more than one object.

It is a mismatch if one needs to create a class to hold behaviour that isn't coupled into any particular object. Classes with only a single method are a bad smell but are common in unittest suites. It's also somewhat conceptually unclear what the object created by such a test fixture is meant to represent.

[more later?]

Python rocks for testing

I'm testing a custom XML-object mapping library. Writing test cases in Python is incredibly pleasant:

class BaseParseTest(comfychair.TestCase):
    def runtest(self):
        tt = pywbem.tupletree.xml_to_tupletree(self.input_xml)
        result = pywbem.tupleparse.parse_any(tt)
        self.assert_equal(result, self.expected_obj)
class KeyBinding_Numeric_Test(BaseParseTest):
    input_xml = """<KEYBINDING NAME="answer">
        <KEYVALUE VALUETYPE="numeric">42</KEYVALUE>
    </KEYBINDING>"""
    expected_obj = {"answer": 42}

and that's it! Rinse, repeat. Add more as problems are discovered.

I'm using my comfychair test library here, which is yet another rewrite of the JUnit idea, specialized for the kind of tests I often write.

In particular:

It's only a matter of degree, but being 50% easier to create test cases has a compounding effect on the amount of test coverage.

Python has much weaker compile-time tests than say Java or C. The ease of writing tests tends to make up for this though, and to get you to a higher state than Java that merely compiles but is not yet tested.

Writing tests will make you happy

Mark Dominus has wise advice on testing:

Writing tests will make you happy

If you make it into a big chore, you won't do it

So don't make it into a big chore

Effective tests can be extremely simple

Rapid Testing

Jason pointed me to James Bach's writing on rapid testing. It looks interesting:

How is Rapid Testing different from normal software testing?

Testing practice differs from industry to industry, company to company, and tester to tester. But there are some elements that most test projects have in common. Let's call those common elements "normal testing". In our experience, normal testing involves writing test cases against some kind of specification. These test cases are fragmentary plans or procedures that loosely specify what a tester will do to test the product. The tester is then expected to perform these test cases on the product, repeatedly, throughout the course of the project.

Rapid testing differs from traditional testing in several major ways:

Archives 2008: Apr Feb 2007: Jul May Feb Jan 2006: Dec Nov Oct Sep Aug Jul Jun Jan 2005: Sep Aug Jul Jun May Apr Mar Feb Jan 2004: Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan 2003: Dec Nov Oct Sep Aug Jul Jun May