In brightest day, in blackest night
No failing tests shall escape my sight!
Let those who sloppy code would write
Beware my power — JUnit’s green light!
OK, it’s kitsch. Tacky. Geeky. Even (shudder) cute. But it also has a point. Bear with me. (I’m assuming you’re a software developer, and already familiar with unit-testing, and Green Lantern.)
I wrote my first Fortran program in 1970. I’ve been coding ever since. These days they call me a “senior architect” — hopefully for my knowledge and experience, and not my grey hair.
But every day, in every shop, in every language, we’re bathed in two feelings:
- Delight. The excitement, the joy, the power, of making these lumps of silicon jump through hoops, stand up and perform miracles at our command.
- Fear. Yes, fear! We write new code in a burst of energy and delight. And then… when we go to change it, or touch code that we didn’t write… we are afraid. Very afraid. Because the faithful digital servant that takes our every instruction as the word of gods… turns on us, savages us in a microsecond, when we err. That is why we unit-test. Oh, people will blather on about Agile productivity, improved ROI, safety-nets, unit-tests as documentation, ad nauseum. But those are just words to convince the blinkered bureaucrats. They will never know the gut-twisting agony and responsibility that we feel, when the spaghetti code slides, like razor blades, through our naked hands.
Why Green Lantern? The parallels are striking:
- To fly on a thought. To weave constructs of energy out of our imagination and willpower. To make a difference! To build where others would destroy.
- Fear is our nemesis. In the emotional spectrum of the DC Universe, green is the color of will-power. Yellow is the color of fear. Originally, Green Lanterns were powerless against yellow. Even now, new Green Lanterns are recruited with Gabriel-like declarations: “Hal Jordan of sector 2814, you have shown the power to overcome great fear“.
Why an Oath?
The Oath came to me in a “flash” in 2011, when I saw the (so-so) Green Lantern movie. The green light of the JUnit test framework merged in my mind with “Green Lantern’s light!”, and the rest was, well, history. Or fantasy. Or whatever.
In the real world, neither a green wrist band nor a comic-book oath is going to help us write better code or more tests. But consider what’s behind the oath.
In the 1994 Emerald Twilight and 2004’s Green Lantern: Rebirth, a troubled Hal Jordan succumbs to Parallax — the literal (yellow!) embodiment of fear, long imprisoned in the master Green Lantern battery on Oa. Jordan nearly destroys the Green Lantern corps, redeems himself by reigniting our dying (yellow!) sun, and finally triumphs over Parallax with the aide of his fellow Lanterns:
John Stewart: Hal, what’s your plan?
Hal Jordan: Remember fear.
Guy Gardner: “Remember fear?” What the hell kind of science crap is that?
As developers, that’s exactly what we need to do. When we don’t acknowledge our fear, we:
- Deny it, and insist on absolutely precise specifications. (“Reaction formation“). “I could write perfect code if only the specifications were correct!”
- Deny the issue entirely, and push it away from the ego: “I’m a brilliant programmer. Tests waste my time.”
- Turn the fear inwards, and obsess. “I’m a careful programmer, I study every possible path of execution.” We hunch over our monitors, and carry the stress home in our bodies.
- Despair, and live in fear. “That’s just the way it is. We’ll always have bugs.” And our delight slowly erodes.
- Look for religion. “If only we faithfully follow six sigma, or CMM Level 3, or all become SCRUM masters, we’ll be saved.”
- Project our fear, and blame everyone else for bad code.
- Avoid the source of our fear. Avoid change, avoid rewriting, avoid refactoring.
- Escape into “if only’s”. “If only we could rewrite the entire project, this time we’d do it cleanly!” Or, “If only I could find a job where things were done right for a change.”
When we face our fear, we…
- Accept the up-front cost of unit-tests.
- Build our own safety nets.
- Sleep better at night!
- And best of all… begin to realize that change can be safe, and even exhilirating. The code that was a mess… can be changed, can be made clean, can be made whole.
That’s why there’s an oath: to remind us. Face your fear. Own your power. And own the green light!
3 thoughts on “The JUnit Green Lantern Oath”
Kent Beck(!!), one of the authors of JUnit, tweeted “The JUnit Oath brought tears to my eyes…” twitter.com/kentbeck/status/227182969272545280