What Happened
Kent BeckNov 10, 2025The Test Desiderata desires 12 properties for tests, :
Isolation—the result of running one test should be completely independent of the results .
Composition—??? tests should run together ??? Isn’t isolation?
No, and here’s why (I finally got an example—examples are always the hardest part.)
Why It Matters
If a setting fixture, creating from scratch , guaranteed to be isolated. It doesn’t matter , the results will be exactly the same. ( property as referential transparency in functional programming.)
Isolation is encouraged testing frameworks () by creating a new instance of a test object & running the setUp() function before running the test. (Some frameworks, notably NUnit, reuse test instances, opening breaking isolation.)
a suite of isolated tests & together. The suite’s success should give us confidence (be predictive in Desiderata terms), even though each individual ’t comprehensive.
test1() object := new Whatever() actual := object.doSomething() assertEquals(expected, actual)
What Comes Next
test2() object := new Whatever() actual := object.doSomething() assertEquals(expected, actual) actual2 := object.nowSomethingElse() assertEquals(expected2, actual2)
I copied, pasted, & extended 6 or 7 times. pretty .
Notice that test2 can’t pass if test1 fails. All non-compliant programs caught by test1 caught by test2. 3 options that preserve the same coverage, the same predictability:
From a purely aesthetic standpoint (& don’t discount aesthetics), leaving offends my sensibilities. They are redundant! Something .
Deleting test1 loses us another property Desiderata—tests should be specific. That’s the property , , you know exactly where the problem is.
preferred solution—composition. I trim test2 purely redundant parts:
test2() object := new Whatever() object.doSomething() actual := object.nowSomethingElse() assertEquals(expected, actual)
Explore more: Software & AI Guide