I recently implemented some serverside argument validation on a peculiar J2EE environment. This system makes it difficult to isolate modules of software, making the HTTP server the only reasonable way to execute the code. There is only one channel of output in this case: the same one that delivers content to users.

Which makes all of my tests integration tests. Unfortunately, since I was focused on some tricky logic, I needed some isolation. I needed a way to get visibility into some of the intermediate values on my calculations. It occurred to me that there is an out-of-band channel I could use:

HTML Comments

So I started encoding some debugging values in JSON, emitting them as HTML comments in the output. Then I built a ruby script to Curl this page with different arguments, parse all of these JSON blocks and compare the results against expectations.

It is a fairly dirty approach, and is likely to be removed before release to production, but it let me TDD a tricky problem. It was far simpler than introducing traditional view testing approaches, and got me the isolation I wanted.

In a pinch, look for those out-of-band communication channels like inline comments or console logs for reliable access to internal state. And anything that’s reliable can be used for automated testing.