Search code examples
formsunit-testingcaptchatapestry

Pattern for unit testing a form with a Captcha component inside?


I am currently faced with the difficult task of unit testing a form with a Captcha component inside.

By definition, a Captcha is intended to prevent automatic submissions. And by definition, unit tests are automatic.

Can someone well versed in unit testing html forms please provide advice?

(FYI, I use Tapestry 5 together with its bundled Kaptcha component - although I suspect the solution is not technology-dependent.)


Solution

  • I add a test mode to my application that forces the Captcha string to a well known value (I like "i8cookies"). The test mode is specified as a JVM system property at startup and simply isn't present in production mode.