Tuesday, September 30, 2008

the binary canary testing pattern



I think I just invented a new testing pattern - The Binary Canary.

Basically, I was grouping my PHPUnit tests into a test suite and I realized that my TestCase super-classes were "failing" because they had no tests in them. Obviously this is intentional - only the specific sub-classes would have tests.

I guess I could have made the TestCase super-classes abstract, but instead I added this to the highest-level TestCase class:

/*
* global test plumbing here
*/
class Sfx_TestCase extends PHPUnit_Framework_TestCase
{
public function setUp()
{
// more global test plumbing here
}
public function test_Binary_Canary()
{
$this->assertEquals(
"Binary Canary says test plumbing is working.",
"Binary Canary says test plumbing is working."
);
}
}

My little binary canary serves two purposes:

  1. It adds an "always-pass" test to each of my TestCase classes so they don't throw up any more PHPUnit warnings.

  2. Because my TestCase classes set up context-specific test plumbing, the binary canary test inherited by each of them now alerts me if I screw up any of my test plumbing - and tells me the specific area.


For example:

class Sfx_Db_TestCase extends Sfx_TestCase
{
public function setUp()
{
parent::setUp();
// Db-specific test plumbing
}
}

And:

class Sfx_Controller_TestCase extends Sfx_TestCase
{
public function setUp()
{
parent::setUp();
// Controller-specific test plumbing
}
}

Just like the coal-miner canaries of old, this mechanism gives me a simple yes/no signal as to whether or not my test plumbing will soon kill me, and which plumbing code is the culprit.

Friday, September 26, 2008

bailouts

I usually try to avoid preachy blog postings, but I can't help it today. Blame it on "casual Friday" or something.

Like lots of people, I'm pretty angry about the government using our taxes to bail out Wall Street incompetence. But now I've gone from angry to pissed-off. Here's why ...
The Dot-com bubble crash wiped out $5 trillion in market value of technology companies from March 2000 to October 2002.[11]

Recent research suggests, however, that as many as 50% of the dot-coms survived through 2004, reflecting two facts: the destruction of public market wealth did not necessarily correspond to firm closings, and second, that most of the dot-coms were small players who were able to weather the financial markets storm.[12]

--http://en.wikipedia.org/wiki/Dot-com_bubble#Aftermath


Not only do I work for a dot-com survivor, I work for one of the most bruised, battered, and beaten-up dot-com survivors. I mean, just check out our stock chart! I haven't asked around the office for official corporate history or anything, but I'm pretty sure no-one remembers getting a couple billion dollars from the government while the company lost close to 99% of its market value, but I have been told there were weekly, if not daily, downsizing announcements.

Now I'm not jealous or vindictive on the part of my company - I wasn't even around for the toughest times. I'm just making a point here that market "catastrophes" and "crises" have happened, happen, and will always happen. Sadly, people will lose their jobs, their wealth, and their houses. In the case of the dot-com fallout, $5 trillion worth on Wall Street alone plus whatever subsequent losses are tallied.

6 weeks ago, the Congressional Budget Office said taxpayers would need to spend $25 billion to bail out Fannie Mae and Freddie Mac. Now we are seeing figures up to $700 billion. The figure could very well balloon to beyond the $5 trillion lost in the dot-com burst, no-one really knows - not you, not me, not Wall Street, and not Washington.

So why are we even considering footing the bill for this when no-one even knows what the total is, how it's going to be paid, or to whom we pay it? Obviously there are some very powerful financial market players gaming the system. They are not the "small players who [are] able to weather the financial markets storm."

It would be interesting to see if the Financial/Credit/Mortgage-Lending industry follows a Long Tail distribution. Might be a case of the tall head exploiting the public to avoid their necessary chop down to obscurity ...

Wednesday, September 17, 2008

unit tests and just-got-it-working inertia

I've been reading and enjoying The Productive Programmer by Neal Ford. It has re-ignited some of my passion for Test-Driven Development.

This morning I finished a first phase of "refactoring" some code architecture and found myself extremely hesitant to dive straight into the next phase. I think it's because the extent of my "testing" was to tab over to the fully-functioning web page and refresh after each code change. That's pretty much an "all-or-nothing" scenario.

And the thing about all-or-nothing scenarios is that once you've achieved the "all" state, you're very hesitant to go back to the "nothing" state. Maybe I'm starting to understand one of the benefits of unit tests as opposed to whole-sale acceptance tests. With smaller unit tests, you can move more concretely from nothing to something, then from something to something a little more, then finally to all done.