test isolation: default ignores & repository acquisition

Martin Pool mbp at canonical.com
Fri Sep 18 00:06:58 BST 2009


2009/9/18 Vincent Ladeuil <v.ladeuil+lp at free.fr>:
> Exactly what I pointed in an another mail, the tests shouldn't
> start with a local setup if that could be factored out at the
> class level, thanks for demonstrating my point.
>
> Having setUp() methods makes smaller and more readable
> tests. Smaller tests provides better defect localization, by
> design.

I think separating out common code is (of course) good, but I do not
feel very convinced that putting it in setUp(), as opposed to an
explicitly called make*() method is a good idea.  It is less explicit,
it doesn't seem much shorter, you can have bugs with not calling the
superclass setUp(), and addCleanup is better than putting cleanup it
tearDown.

In other words I prefer

  def make_branch_with_history(self):
    branch = self.make_branch()
    ...

  def test_some_thing(self):
    branch = self.make_branch_with_history()
    ...

to

  def setUp(self):
    super(SillyPythonTest, self).setUp()
    self.branch = self.make_branch()
    ...

  def test_some_thing(self):
    check_something(self.branch)


-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list