Given the following simple example:
class MathObject(object):
""" A completely superfluous class. """
def add(self, a, b):
return a + b
def multiply(self, a, b):
result = 0
for _ in range(b):
result = self.add(result, a)
return result
Obviously, multiply() calls add() internally. If add fails, multiply() fails too. In a complex enough class it might be really complex to find out why exactly a unit test failed.
How does one unit test methods/objects/parts that have dependencies?
I usually just let them fail – classes should be simple enough to spot the bad test fast.
But, in complex cases we’ve used simple naming conventions for tests to make sure a certain order is kept (
def test_00_add,def test_01_multiply).Again, if your classes get big this will be harder to manage, so just don’t get them big 🙂