Time to start Acceptance Testing

After returning to the Moneyjar web application after a long haitus, I was surprised to find the build would not compile. At all. The classpath was broken, and there were errors all over the place. So I thought it would be a good idea to fix it. That was my first mistake.

I started rearranging all the libraries, adding and removing libraries from the classpath in a desperate attempt to get it working again. But the more I changed the more those changes came back to bite me. But honestly, when I first started reconfiguring my project I just didn’t think it would be that far from compiling again, after all, I hadn’t touched it, so how broke could it be?

So, after an entire wasted Sunday digging around the project exploring the class path and build configurations, it occurred to me that what I should have done was remove the entire project and imported back to the previous stable build. Whoops.

However, once I got the program compiling again I fired up the server, and … nothing. Nada. The application failed to load and I was getting the 404 not found message. Scratching my head I began to investigate. Compile errors, nope. All clear. Warnings, nothing relevant. Unit tests, all passing. Great so why won’t it load? I began inspecting the Tomcat logs, and it was being especially cryptic.

It turns out I had at some point removed some libraries that I thought were redundant, but had actually contained important jars. Which I later added using Ant and Ivy to manage all my dependencies. This led to initialization problems. The culprit was a servlet-api jar that didn’t belong in the war package. So after a little head scratching I imported some missing libraries in my ide, and removed libraries from the ‘lib’ directory that would eventually get packaged into the war file.

Job done. Or so I thought. After reloading the server, still nothing. Instead I got a host of new errors, something about my hibernate classes throwing exceptions. A Hibernate utility class was failing to load, but why? Is it a bug? After a bit more head scratching and several aha moments, it dawned on me that it was a configuration issue that dated back to long before I had broken the build. The issue was that my integrated desktop environment has no problem building the application, but the Ant build and Tomcat could not run it. Why? Because I forgot to package the hibernate configuration file into the war package. Also I has managed to get the database URL wrong in the configuration file.

Both if these issues, that I had wasted many hours on, as it turned out were problems long before the build failed. After all, the classes were compiling, and the tests were passing. But the application did not run, and had broken around the same time I included hibernate and an external servlet-api jar, which was a long long time ago. It just goes to show that sometimes a compiling program, and passing unit tests can lead you into a false sense of security. You could argue that the problem was integration testing. But perhaps the better option is to see the application running.

Time to learn Fitnesse and Selenium! Fitnesse is an acceptance testing framework, that ensures that all the individual classes and packages are working together to produce some expected result. Selenium is a frame work that allows you to programmatically drive a web browser. Used together we can ensure that all the classes are integrating nicely, and also that the application runs as you would expect.

I had been thinking that I could get away without Fitness or Selenium in my project. Largely because I didn’t want the additional overhead. But I have now been proven wrong. What is surprising though, is that I think I have as much configuration and framework code than I have any production code. But then again, this project was to help me learn about these tools and best practices so on that front, I’m doing very well.

Comments are closed.

Powered by WordPress. Designed by Woo Themes