Please forgive a cross-post... this is relevant to both groups. And
although this is specific to coldbox, I imagine there are corollaries
in model-glue, mach-ii, etc.
OK, so, coldbox comes with a set of base tests to make testing event
handlers easier. This is possibly more along the lines of integration
testing in that you're testing the entire event execution and not just
In the quick-generated tests that come with coldbox, for example in
generalTest.cfc, you'll see this:
<cffunction name="testonException" access="public" returntype="void"
//You need to create an exception bean first and place it on the
request context FIRST as a setup.
var exceptionBean =
var event = "";
//Initialize an exception
exceptionBean.init(erroStruct=structnew(), extramessage="My unit
test exception", extraInfo="Any extra info, simple or complex");
//attach it to request...
form.exceptionBean = exceptionBean
//TEST EVENT EXECUTION
event = execute("main.onException");
//Do your asserts HERE
This will work fine if you run the test in the browser, either via
generalTest.cfc?method=RunTestRemote or via a DirectoryTestSuite in a
.cfm file. However, this will fail if you run the test in the plugin.
You'll get an error that exceptionBean is not defined in form.
The reason is that the plugin interacts with CF via webservice (SOAP)
calls, and thus the form and url scopes are not present... they're not
defined at all. This came up quite some time ago and I don't think we
ever found a good way to solve it. Now, possibly using some
elliot-sprehn-like magic, we could hook into some service 5 levels
deep and get at it, but I don't have the time, intelligence, or energy
for that. So, I wanted to show the super simple way of getting around
this in coldbox.
instead of attaching data to the form scope, simply add it directly to
the request context itself, which is conveniently made available in
the base test. You do it like so:
In essence, this is doing the same thing you'd do when you attach the
data to the form scope, because under the hood coldbox just merges the
form and url scope into the requestcollection anyway.
So, for those of you using mxunit and coldbox, and who are attempting
to test your event handlers, that's how to do it in the plugin.