Unit testing – why? Part 1: Out -of-container testing

Unit testing is great for my core programming duties. I write a lot of code that runs in an application server, maybe jboss or weblogic. I don’t always want to deploy this code to test how it works. I may want to run it quickly, in isolation, with a certain parameter and see what happens. There may be 6 or 7 different scenarios and I want to run through them in rapid succession, without having to build, deploy, login, set up any necessary data. This is where my unit test comes in. This is the simple reason for a lot of unit tests – I want to invoke my method and I want to do it now!

This was the first thing that struck me about unit testing, running code away from the slow build cycle. At a push you could do it with a simple public static void main method but JUnit gives you nice features to make it easier and more fun – an Assert class to help compare expected and actual results, a way of running multiple tests, great eclipse integration and it will fit into your continuous build too.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s