« Beware of unlocalised JREs | Main | Python Paradox makes sense... »

Why it's important to be able to unit test outside the container

Daniel Steinberg has a note on Java.Net about testing EJBs out of the container, and wonders why people make a fuss about it. There's a simple reason: speed.

I run my unit tests a lot; I would run localised subsets of the tests every couple of minutes, and the full test suite at least once an hour if not more1. Running inside a container isn't slow, but getting the code there sure is, by comparison.

It's not hard to write your code so that you have a set of POJO-ish objects which are given services provided by the container. This makes unit testing reasonably straight-forward. Your integration tests, then, must ensure that you correctly set up the services for your POJO objects (and yes, you need integration tests). Obviously, integration tests need to run in-container.

This also means you don't unit test everything outside of the container; it is obviously rather pointless to do a lot of unit testing around the glue code (just enough so that you have a reasonable degree of confidence with it).

One of the nice things about using IoC/dependency injection as a style of coding is that you can easily set up your EJBs or Servlets to inject the dependencies for you into your POJO classes.

----

1 One of the standard hints about good typing is to take a break every hour; I hit the full-build button just before having the break.

Post a comment


About

This page contains a single entry from the blog posted on August 8, 2004 9:43 PM.

The previous post in this blog was Beware of unlocalised JREs.

The next post in this blog is Python Paradox makes sense....

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35