The Zero-One-Infinity rule is a computer science adage from Willem van der Poel meant to compel software designers to avoid arbitrary limits. In thinking about this recently, I’ve come to appreciate zero-one-infinity as a useful heuristic for certain categories of…
Wake up again (and again)!
Previously, I wrote about a simple way to change slow, time-sensitive tests into fast, no-wait tests using some async tricks. However, the example shown only works well when the underlying slowness involves a one-shot action. What if instead you are…
Destroy all* tests: unit test edition
Sometimes the code we need to write is so simple that we cannot imagine getting it wrong. Going test-first in these cases just seems apt to lead to tedium and tautologies. This could be a fair point if the sole…
Blogging on logging
Everyone loves a log. A trace log can provide insight into the goings-on of a running system. An audit log gives you an important “paper trail” tracking who did what and when. An error log might be an important aid…
Orchestrating race conditions
Many a programmer has struggled with unit tests and those pesky race conditions that are seemingly immune to them. Is it even possible to verify concurrency correctness using TDD? I am going to tell you that it is — sometimes.…
Laziness is a virtue
Sometimes you want lazy initialization but your initialization function is asynchronous. Stephen Toub wrote about this conundrum years ago on the pfxteam blog. The solution as he describes it is fairly straightforward — use Lazy<T> combined with Task<T> and you’re…
Object Mother and Tasks
In a previous post “Fluent async testing,” I introduced a sample library to beautify unit tests relying on Task-based assertions. Tests for this type of library typically make heavy use of “canned Tasks” to ensure every case is handled correctly.…
Wake up!
In Effective Unit Testing: A guide for Java developers, author Lasse Koskela writes about the scourge of the sleeping snail — slow tests littered with calls to Thread.sleep. His suggested alternative is perfectly sound and practical: turn nondeterministic waiting into…
Gratuitous complications: unit test fault injection
Sometimes things don’t need to be complicated. I would go so far to say most of the time things don’t need to be complicated. In the words of Uncle Bob Martin, “it is the software engineer’s job to make tough…
Fluent async testing
Cellfish writes: When .net 4.5 was first in public beta most test frameworks had a bug making it impossible to write async test methods. I wish they had never fixed that because I don’t think those help you write good…