JUnit changed my life

A few months ago, Vic was talking about JUnit and how I should have been making use of it. He even went so far as to sketch out a small test case. I knew I should have been writing test cases for my code, but my work schedule was so hectic, with me needing to stay one step ahead of five client-side developers, that I just assumed I didn’t have the time. Besides, where to begin? I was too busy for testing!

A couple of months later I found myself working late and making changes to the way data was marshaled to the client. It was at this point that I would have bounced my server and told the client developer for the project to “Try it now!”. However, the client developer had already gone home for the evening and I didn’t want her waiting on me early the next morning. Suddenly, as if in a ghostly vision, I saw Vic hovering before me intoning “Use the JUnit, Ian”. Seconds later I performed a few searches on Google, came up with this document and within minutes was writing my first JUnit test case. Thanks to IDEA with JUnit testing and debugging built-in, it was a snap and couldn’t have taken more than ten minutes.

Now I write JUnit test cases all the time and love it! As well as exposing flaws in code, particularly in marshaling methods, which might not have been executed until later, JUnit has speeded up development in some areas. Even better, by requiring that my code be more modular in order to facilitate testing, JUnit has revealed useful refactorings which needed to be performed. Code which I didn’t think could be easily tested because it relied on either a pre-defined set of actions or on outside data, is now cleaner because of JUnit testing.

Thanks, JUnit! You changed my life!

Leave a Reply