« Killer Bees!
Main
A Breakfast Haiku »
We loves the green
One of the refreshing changes in my new job is that one of the large core pieces of our system is very easy to JUnit test. I hate that unit tests can't be brought to bear on more kinds of problems, but when they can, boy it is satisfying.

Today, for example, in order to fix a frustrating bug I had to learn how to use JavaCC grammars for the first time. Powerful it may be, but if you're trying to understand machine-generated code with variables named "jj_la1_0", it's difficult to feel confident monkeying with a grammar. Hard to know what's going on, very easy to screw something up.

JUnit to the rescue. This is one of the situations where I actually do test-driven development--- I pre-write tests that start out green to prove that I didn't break the system. And then I pre-write even more tests that start out red to prove that my fix isn't working yet. And then I keep tinkering until they're all green.

But there's an arguably even greater benefit of JUnit than the red/green: you can run in a cleanroom environment. That means:
  • You don't have to wait to rebuild and re-initialize the entire integrated system
  • You don't have to click through the GUI to exercise your code
  • You can debug without stepping through thousands of false positives to get to the part of the system that you're working on
  • When something breaks you don't have to wonder if the code you changed interacted with something else
  • When something works you don't have to wonder if some other part of the system is masking an error
And at the end I had it all working, and I know it works because the little bar is green. Yay!
Comments
blog comments powered by Disqus
The views expressed on this site are mine personally, and do not necessarily reflect the views of my employer.