Writing for Untestability. · 29 July, 08:36 AM

via Steve Loughran, How to Write 3v1L Untestable Code on the Google Testing blog. The “Use Global Flags” rule cracked me up, except that my variation on the rule for .NET would be “Use appSettings liberallly”. It’s another reason to dislike appSettings, except that it’s more evil, because a simple “find references” won’t reveal it the way it’ll reveal global flags. So to generalize, the rule is “Depend on configuration for everything”, because the alternative, to use configuration objects and pass those in as initial state, requires a little more work but yields more testable code – particularly in .NET where the app.config is tied to the AppDomain. The “Depend on Large Context Objects” is along the same lines rings totally true for anybody who’s had to deal with anything around System.Web.

But Steve’s absolutely correct about the “Use Utils Classes” and “Use statics” rules – the reasons those smells show up in every project is because of sealed, final and their ilk. Except that I’m sure there’s a Ruby / Python version of this floating around that has a rule like “Override low-level methods of object whenever the opportunity arises”.

— Gordon Weakliem

---

Comment

Commenting is closed for this article.