Monday, May 10, 2021

What is a Testable Unit?

Last week I had a conversation with my good friend, John Hubb, about the various philosophies of TDD (Test Driven Development). This harkened me back to the halcyon days of my ACCA/ARGON lectures at Concordia where I met James Coplien, and his various musings about Unit Testing, TDD, BDD (Behavior Driven Development) and Agile methodologies.

The stand-out observation for me was the question, "What is a testable unit?" Modern developers, especially in object-oriented languages, tend to think every public class is the testable unit. Coplien challenges this notion, to think about functional units of code, with externally verifiable expectations, are the unit, and around which quality unit tests will congregate. Think business expectations, e.g. "Given X, when Y, then Z," and not "When I invoke this public function with A, it should return B."

"Tests should be designed with great care. Business people, rather than programmers, should design most functional tests. Unit tests should be limited to those that can be held up against some 'third-party' success criteria."

-- James Coplien, Why Most Unit Testing is Waste

No comments:

Post a Comment