tags:

views:

30

answers:

2

I want to test validation logic in a legacy class. The class uses a method to load effective dates from a config file.

I have written a subclass of the class in question and overridden the config method so I can run my unit test against the subclass with any combination of effective dates.

Is this an appropriate strategy? It strikes me as a clean technique for testing code that you don't want to mess with.

A: 

I like it, its the most simple and straight forward way to get this done. And since it is a legacy class, it will not change anymore, so you don't run danger of bumping into the fragile base class problem neither.

Adrian
A: 

It seems to be an appropriate strategy to me. Ofcourse with this override you won't
be able to test the code (in the original class) that loads the config data, but if you have other tests to cover this sceario then I think the approach you outlined is fine.

sateesh