Unit Testing Web Apps

I’ve spent the last couple days in between meetings and fighting fires trying to review two Struts projects my teams are working on. I keep trying to add tests only to find that it’s much harder to add any sort of meaningful test than it should be. These are not big applications and they’re being done by developers on learning curves who aren’t too OO familiar so the bulk of the code and logic is in JSPs or Struts Actions. Unfortunately that means they’re immediatly hard to test. So far these are the things I keep running into:

  • The easiest tests are functional end-to-end tests using something like JWebUnit, but brittle and they take too long to run to do more than a few.
  • StutsTestCase just doesn’t provide to much besides firing off an action from the mapping file and seeing if it creates the expected results. Generally it just feels to trivial.
  • JSPs are just a pain to parse and have to be rendered anyway especially since tiles and the like are in use. And generally what does parsing a JSP really tell you. You end up in the GuruTestsCode pattern real fast.
  • You can write tests around the DAO layer, but generally you’re just testing against the live database, again too slow.
  • There are always some validation Utility classes, that at least are easily testable

I’m going to circle the wagons tomorrow and bang some ideas off my top developers, but I’m beginning to think without rethinking the design for testability that unit tests don’t work to well in this environment.