Miniformats for Tests
So you’re building out a fairly complex component — one of those things that, try as you might, you really can’t simplify any further. Consider what happens when you start building out your tests for this component. You get all your really basic unit tests done quickly — things like • “ make sure this function returns a positive integer ” • “ validate that the user count is never zero ” and so on. The fun begins when you start layering on functionality. For example your widget’s state includes a whole bunch of opaque internal structures with a variety of bit-patterns, hashes, and whatnot — and your widget does…stuff…based on these structures. Your tests very rapidly end up containing depressingly long sections of code, all designed to say stuff like // set up my widget var widget = new Object(); widget.hash_start_section = "deadbeef"; widget.constructor_type = 1337; . . // continues forever... And that’s on a good day. On a bad day, you do horrible stuff like seriali...