List of currently supported Matchers

Table 2. SQLUnit Matchers

Matcher NameAuthorDescriptionArguments
AllOrNothingMatcherSujit Pal (spal@users.sourceforge.net)The AllOrNothingMatcher is an implementation of the IMatcher interface used to define rulesets for matching columns in SQLUnit. This implementation is of no particular use, except as a template for other useful matchers and for testing. Based on the argument supplied to it via the argument map, it will either always returns true or false for the column being matched.

match : Always returns true if set to true, else always returns false.

SignificantDigitsMatcherTim Cull (trcull@yahoo.com)The SignificantDigitsMatcher is an implementation of the IMatcher interface used to compare FLOAT values where you only really care about matching to a certain number of significant digits to the right of the decimal. Especially useful when you're generating your test script by copying and pasting out of a SQL query tool that displays a different number of significant digits than SQLUnit pulls back from the database. Example configuration: <match resultset-id="1" row-id="*" col-id="9-13,15-18" matcher="net.sourceforge.sqlunit.matchers.SignificantDigitsMatcher"> <arg name="signif-digits" value="3" /> </match>

signif-digits : Number of significant digits to match to

TypelessMatcherSujit Pal (spal@users.sourceforge.net)The TypelessMatcher matches column values only from two different SQL or stored procedure calls. This would be useful when the data returned from two different databases may have the same String value but the actual datatypes they are implemented as may be different. This is the matcher that is used implicitly when the assertion "resultset-values-equal" is called.

None : -

RangeMatcherSujit Pal (spal@users.sourceforge.net)The RangeMatcher is an implementation of the IMatcher interface used to define rulesets for matching columns in SQLUnit. This matcher will accept an absolute tolerance value and check to see that the target is within (+/-) tolerance of the source.

tolerance : An absolute tolerance value.

PercentageRangeMatcherSujit Pal (spal@users.sourceforge.net)The PercentageRangeMatcher is an implementation of the IMatcher interface used to define rulesets for matching columns in SQLUnit. This matcher will accept a percentage tolerance value and check to see that the target is within (+/-) tolerance percent of the source.

pc-tolerance : A percentage tolerance value.

TypelessPercentageMatcherChris Watts (c_watts@users.sourceforge.net)The TypelessPercentageMatcher matches columns which may differ by a specified percentage. This can be useful when comparing numeric values across data types which have different default precisions.

pc-tolerance : A percentage tolerance value.

ForgivingNullMatcherTim Cull (trcull@yahoo.com)The ForgivingNullMatcher is an implementation of the IMatcher interface used to compare values you know are either supposed to be NULL (but might be textually represented differently) or are actually equal. Basically searches for the word NULL (case insensitive) or for blank elements or for elements that are equal Strings. Especially useful when you're generating your test script by copying and pasting out of a SQL query tool that displays NULLs differently than SQLUnit pulls back from the database. For example, all of these values are treated as equal: <col id="14" name="benchcode" type="INTEGER">[NULL]</col> <col id="14" name="benchcode" type="INTEGER">NULL</col> <col id="14" name="benchcode" type="INTEGER"></col> <col id="14" name="benchcode" type="INTEGER">null</col> Example configuration: <match resultset-id="1" row-id="*" col-id="14" matcher="net.sourceforge.sqlunit.matchers.ForgivingNullMatcher"> </match>

None : -

ExpressionMatcherSujit Pal (spal@users.sourceforge.net)Allows the caller to specify an expression in Apache JEXL (Java Extended Expression Language). The expression must evaluate to a boolean expression (true or false). The source and target are referenced in the expression using the pseudo-variables expected.value and actual.value.

expression : A valid JEXL expression. Source and target variables in the expression are referenced by the pseudo-variables expected.value and actual.value respectively.