Skip to content
Tech News
← Back to articles

Kent Beck: Composable Tests

read original more articles
Why This Matters

Kent Beck's article emphasizes the importance of designing tests that are both isolated and composable, ensuring reliable and maintainable testing practices. Properly balancing these properties enhances confidence in software quality and simplifies test management, which is crucial for the evolving demands of the tech industry and consumers who rely on robust applications.

Key Takeaways

The Test Desiderata desires 12 properties for tests, two of which are:

Isolation—the result of running one test should be completely independent of the results of other tests.

Composition—??? tests should run together ??? Isn’t that the same thing as isolation?

No, and here’s why (I finally got an example—examples are always the hardest part.)

Isolation

If a test runs by first setting up its own test fixture, creating from scratch all the data it will be using as input, then that test is guaranteed to be isolated. It doesn’t matter what order you run the tests, the results will be exactly the same. (This is the same property as referential transparency in functional programming.)

Isolation is encouraged in the xUnit testing frameworks (at least most of them) by creating a new instance of a test object for every test & running the setUp() function before running the test. (Some frameworks, notably NUnit, reuse test instances, opening the door to breaking isolation.)

Composition

Say we have a suite of isolated tests & we run them all together. The suite’s success should give us confidence (be predictive in Desiderata terms), even though each individual test on its own isn’t comprehensive.

Example—say we have a test:

... continue reading