I am working on a unit test for a complicated, multi-step procedure. Conceptually it is something like this:
def complicatedStuff(self):
self.step1()
self.step2()
self.step3()
Ideally I would like to write tests for each step:
def test_step1(self):
self.obj.step1()
def test_step2(self):
The problem is that the setup for each step is complex. The best way to set up to test step3() is to do step1() and step2(). So I have settled for a single test method that has the same structure as complicatedStuff():
def test_complicatedStuff(self):
self.obj.step1()
self.obj.step2()
self.obj.step3()
This smells. It is a clear violation of Don't Repeat Yourself - the structure of complicatedStuff() is duplicated. As a result it is fragile. If the structure of complicatedStuff() changes, test_complicatedStuff() has to change the same way. On the other hand, it works, which is worth a lot!
|