SQLUnit Assertions

List of currently supported Assertions

Prior to version 4.0, SQLUnit only allowed for matching two results for equality, or for matching specific columns using a matching criterion defined by one or more MatchPattern objects. SQLUnit now allows the caller to specify an assertion that should be satisfied for a given test as an attribute of the test, diff and batchtest tags. The change is backward compatible, so if the assert attribute is not specified, it defaults to "equal" in case of diff and test, and "batch-equal" in case of batchtest. Both these default assert attributes are actually macro-assertions, and are composed of a comma-separated series of assertions. These assertions, along with some new ones, can be specified either individually or in a sequence that makes sense in the context of the test case.

The assertions that are currently supported by SQLUnit are shown below:

Table 1. SQLUnit Assertions

Assert-StringDescriptionUsed In
noneAsserts nothing about the generated and the actual results. This is typically used to disable assertions for the particular test.diff,test
equalAsserts that the two results are equal. This is actually a macro assertion, which resolves to a number of subassertions, which are asserted serially. This is the default assert if not specified in a diff or test tag.diff,test
not-equalAsserts that the two results are not equal. This is an inversion of the equals assertion.diff,test
exception-matchesAsserts that the two results have identical exceptions.diff,test
not-exceptionAsserts that the result returned is NOT an exceptiondiff,test
number-outparams-equalAsserts that the two results have the same number of outparam elements.diff,test
outparams-equalAsserts that the outparams in both the results are equal.diff,test
update-counts-equalAsserts that the update counts in the two results are equal.diff,test
number-of-resultsets-equalAsserts that the number of resultsets in the two results are equal.diff,test
resultsets-equalAsserts that the resultsets are equal, or match if the test contains embedded match tags.diff,test
resultset-values-equalAsserts that the columns in the specified and actual resultset have the same values. No assertion is made for types.diff,test
resultset-types-equalAsserts that the columns in the specified and actual resultsets are of the same type.diff,test
fail-with-failureAsserts that the test will fail with the specified error message.diff,test
noneAsserts nothing about the generated and the actual batch results. This is typically used to disable assertions for the particular test.diff,test
equalAsserts that the two batchresults are equal. This is a macro assertion, composed of a sequence of assertions, which are executed serially. This is the default assertion if no assert attribute is supplied for the batchtest tag.batchtest
not-equalAsserts that the two batchresults are not equal. This is the inverse of the equal assertion.batchtest
failed-at-equalAsserts that the failed-at attribute of the batchresult tag, if specified, points to the point where the result generated by the batchcall or batchsql actually failed.batchtest
expected-count-equalAsserts that the number of update counts specified in the expected batchresult, either as an expected-count attribute, or listed explicitly, is the same as the one in the generated batchresult.batchtest
updatecount-equalAsserts that the updatecount values are the same for the result specified by batchresult and the result generated by the call to batchsql or batchcall.batchtest
fail-with-failureAsserts that the test will fail with the user-supplied failure message.batchtest