So I have this class I'm testing and it is a helper that pulls stuff out of an XML class. The whole thing is kind of a Russian Doll where you have to dig through several levels to get the right thing you need. Problem is that this class calls many of it's own methods which makes it pretty hard to test without a bunch of redundancy. This is to say that I don't want to retest any of those "low hanging fruit" methods that retrieve objects from shallow locations if I can avoid it. I smell an opportunity for a re-factor here but I'm unsure what it should be. Note that there are often 6 and 7 levels to our "Russian Doll". My intuition says that I should maybe refactor the class under test to a hierarchy of classes, roughly one for each level in our "Russian Doll". Then maybe I could test one at a time without redundancy.
Questions: What are the patterns I should be looking at for this? Is there an approach for doing this which is Composition rather than Inheritance based?
Aucun commentaire:
Enregistrer un commentaire