[rfc] add a TestFactory class or concept

Aaron Bentley aaron at aaronbentley.com
Thu Aug 6 21:25:35 BST 2009

Hash: SHA1

Martin Pool wrote:
> Lots of tests are run on some specific values; for instance they make
> a branch and then do some operations on it.

We need specific values in order to make assertions about them, and to
provide legibility.  Could you please explain what about this is bad?

> I was talking to jml the other day and he said that Launchpad have a
> cleaner separation of all of this setup into a TestFactory class

Cleaner or not, I find bzr's approach much easier to use.

> (iirc) - if you want a Person to test, you would always get that from
> the factory rather than putting arbitrary example data into the class.

I don't understand.  There are plenty of examples where we create Person
objects with specific email addresses and names.  Look at this method

    def makePersonNoCommit(
        self, email=None, name=None, password=None,
        email_address_status=None, hide_email_addresses=False,
        displayname=None, time_zone=None, latitude=None, longitude=None):

These are all the things we've felt a need to specify in one test case
or another.

It's true that we don't have to specify anything at all to makePerson.
If you were arguing that we should improve our existing helpers, I could
understand that, but I don't see how it relates to a TestFactory concept.

> There are some tools such as BranchBuilder to do this.  There are also
> some utilities on TestCase and similar to provide dependencies, and to
> integrate with test parameterization - for example
> TestCase.get_transport() and the implicitly provided working
> directory.  On the other hand a lot of tests hardcode some test data.

I find that concrete examples are easier to understand when you get test
failures.  For example, if you get an exception containing a branch
path, and the branch path includes the test case variable name, it's
much easier to see what's going on.  I've never used BranchBuilder, for
example, and hardly ever used MemoryTree.

Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the bazaar mailing list