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.