assertRegExp

0 views
Skip to first unread message

Mike Henke

unread,
Apr 23, 2008, 12:53:06 PM4/23/08
to mxunit
How is the best why to add custom asserts like assertRegExp without
breaking feature MXUnit framework updates?

billy

unread,
Apr 23, 2008, 2:53:28 PM4/23/08
to mxunit
Hi Mike,

Try these ...

1. In setUp() call
addAssertDecorator("path.to.your.assertion" [,override=true|false]);
if true, override tells the framework to give preference to any
identically named assertions to the custom assertion, effectively
overriding mxunit's assertion. Note, however, that mxunit expects
*mxunit.exception.AssertionFailedError* when an assertion fails so,
you will
need to throw that in your code accordingly.

2. Instead of calling addAssertDecorator(...), you can edit /mxunit/
framework/mxunit-config.xml. Look for a line, that looks like this
and change to fit your config: <config-element
type="assertionExtension" path="path.to.your.assertion"
autoload="true" override="false" />.

#2 does the same thing as #1 but will make your assertions available
to any tests automatically.

This has not been extensively tested, but comments and suggestions are
always welcome! We're still working on documenting this and other
goodies.

hth,
bill

Mike Henke

unread,
Apr 27, 2008, 7:37:09 PM4/27/08
to mxunit
Thanks. I haven't worked on the assertRegExp yet, but was wondering
adding assertNotEquals and failsEqual to Asserts.cfc in mxunit's
build?


<cffunction name="assertNotEquals" access="public" returntype="void"
hint="Core assertion that compares the values the EXPECTED and ACTUAL
parameters. Throws mxunit.exception.AssertionFailedError.">
<cfargument name="expected" type="any" required="yes" hint="The
expected object to compare." />
<cfargument name="actual" type="any" required="yes" hint="The
actual object to compare." />
<cfargument name="message" type="string" required="no" default=""
hint="Optional custom message to display if comparison fails." />

<cfset var expectedStringValue = "">
<cfset var actualStringValue = "">
<cfset arguments = normalizeArguments("equals",arguments)>
<cfset expectedStringValue = getStringValue(arguments.expected) />
<cfset actualStringValue = getStringValue(arguments.actual) />
<cfscript>
if (isNumeric(arguments.expected) AND isnumeric(arguments.actual)
AND arguments.expected eq arguments.actual){
failEquals(arguments.message, expectedStringValue,
actualStringValue);
}
if (expectedStringValue is "" AND actualStringValue is ""){
failEquals(arguments.message, expectedStringValue,
actualStringValue);
}
if (expectedStringValue is not "" AND
expectedStringValue.equals(actualStringValue)){
failEquals(arguments.message, expectedStringValue,
actualStringValue);
}
return;
</cfscript>
</cffunction>

<cffunction name="failEquals" access="public" returntype="void"
static="true" hint="Fails the test and prints the expected and actual
values to the failure message">
<cfargument name="message" required="false" default="This test
failed" hint="Custom message to print in the failure." />
<cfargument name="expected" type="any" required="yes" hint="The
expected string value" />
<cfargument name="actual" type="any" required="yes" hint="The
actual string value" />
<cfthrow type="mxunit.exception.AssertionFailedError"
message="#arguments.message#::[#getStringValue(arguments.expected)#]
EQUAL TO [#getStringValue(arguments.actual)#]" />
</cffunction>

billy

unread,
Apr 28, 2008, 9:40:58 AM4/28/08
to mxunit
Hi Mike,

Good ideas. Let's take this off line and discuss the details w/the
guys.

bill[y]
Reply all
Reply to author
Forward
0 new messages