So the old way to test for an error was something like this:
<cffunction name="ensure_error_on_load_extentions_with_bad_path">
<cftry>
<cfset extManager.loadExtensions(getDirectoryFromPath(getCurrentTemplatePath()) & '/notthere') />
<cfset Fail("Last line should have thrown an error") />
<cfcatch type="mxunit.exception.AssertionFailedError">
<cfrethrow>
</cfcatch>
<cfcatch type="fusebox.BadDirectory" />
<cfcatch type="any">
<cfset debug(cfcatch) />
<cfset fail("Bad Error")>
</cfcatch>
</cftry>
</cffunction>
Now all we have to do is this:
<cffunction name="ensure_error_on_load_extentions_with_bad_path" mxunit:expectedException="fusebox.BadDirectory">
<cfset extManager.loadExtensions(getDirectoryFromPath(getCurrentTemplatePath()) & '/notthere') />
</cffunction>
I love the feature, and I hope others enjoy it too.
3 comments:
Adam, thanks for this contribution! It's awesome. I now see this as a "must have" in any kind of test framework or testing I do.
bill
Just came in super handy for some division-by-zero checking -- thanks, Adam!
In case others were wondering, here is the CF9 script syntax for that:
/**
* @mxunit:expectedException "expected.exception.type"
**/
public void function test_some_thing() {
var foo = do.some.thing()
}
Post a Comment