Nelz's Blog

Mah blogginess

Struts 1.3.X and Testing

We are using Struts 1.3.X at work. (Yeah, it would be nice to use something a little bit modern but due to bad JSF history, internal politics, and the relative immaturity of Struts 2, the decision came down that we are using Struts 1…)

Now, one of my managers had a philosophy that the closer you get to the web tier, the less unit testing you can do effectively. (And this leads us into automated functional testing, but I’m okay with that because I’m a major Selenium fanboy!)

However, since we are really concerning ourselves with PCI compliance, user inputs should be checked at every level. This means we want to ensure heavy-duty validation of user input into forms. In Struts 1, this is done by using the Struts Validator .

Personally, I feel that security is very important, and we should bang through a couple of hundred possible injection strings for every single validation on every form. The sheer number of possible attempts that we are going to want to test leads me away from the much more (time-)expensive functional tests. I would like to do this as a set of unit tests.

Yeah, I could probably pull out some of the Validator classes, throw in a copy of the regexes we’ll be using, and test against those. But that feels false, because then we’re not testing exactly what will be hooked up to our forms at run-time. And there’s no way to ensure the test regexes will get updated when the forms’ declarative checks are updated either.

So, this seems to leaves me with StrutsTestCase. I’ve looked into StrutsTestCase before, and I like that it is a half-step between unit and functional testing, and that it tries to bring testing Struts functionality out of a running container. I don’t care for it because it is written with JUnit pre-4.x in mind.

The problem is that everything I’ve been reading about StrutsTestCase indicates that it is focused on testing the Action classes, and not the ActionForms or their validation.

Another thought just hit me… What if I were to write some kind of testing framework that would just link into some of the classes in Struts, read in the validation.xml file, and provides ways to test the forms that way…? That sounds like a lot of work for a framework that is arguably on it’s way out… (Maybe someone has already written something like this? I’ll see what Google says…)