I’ve finally reached the point where I hurdled my JAXB related validation issues, so another round of full unit testing is called for. Frame2 has two levels of testing:
- Unit tests that can be run outside of a servlet container. These include simple tests on discreet sections of the framework, and some tests written using (ironically) StrutsTestCase to simulate a servlet container.
- Tests that require a live servlet container. These include the TagUnit tests for checking the custom tag libraries and the Cactus tests that verify tag behavior.
The JAXB functionality is tested mainly through the first set of tests. However, as anyone who’s built a web app can attest, things work differently in a container. In this case, I’m talking specifically about loading resources. Using a getClass().getResourceAsStream() works just fine from the Ant console, but returns null when run within Tomcat. The solution, of course, is to use the ServletContext to load the resource, but obviously it’s not available when running outside of the container.
The simple solution was change the loading code to try to get at the ServletContext first, then fail to the getResourceAsStream() call. The best solution would be to refactor the appropriate unit tests so that they use the mock servlet structure – but I’m lazy today and mock objects can be quite tedious. Don’t get me wrong – I have nothing against mock objects. I would just rather get a new release of Frame2 out the door before devoting a lot of time to rewriting the test infrastructure, which is something most end users won’t care about.