Nerdy tidbits from my life as a software engineer

Thursday, April 16, 2009

Designing for Testability

Is it really asking a lot to ask people to make their API’s testable?  It’s so discouraging to me that simple things like service references are 100’s of times harder to test because there is no way to generate them with virtual methods.  So while you can add a command-line flag to svcutil.exe to have it implement INotifyPropertyChanged, you can’t do something simpler like asking it to make all of it’s methods and properties virtual.  And if you can make them virtual, you can test them a lot easier.

And the list of difficult-to-test APIs goes on.  Winforms, the WPF, and my new target of frustration, the Tfs client.  Not only does the VersionControlServer class lack a single virtual method, but it’s also sealed.  Man.  I suppose the problem with not making methods virtual by default (a la Java) is that nobody will do it unless prompted to.  But making your methods virtual is the easiest way to ensure that people can write unit tests that interact with your API.  I’m all for encapsulation, but I also want API’s that I can test against without actually invoking them.

I feel like I’m always fighting against the tide to promote testable APIs, and it’s very frustrating.

0 comments: