There is no clean way to automate failure testing in SQLUnit. By that I mean, that if I want to incorporate scenarios that end in failure, then I have no way to tell SQLUnit:
here is a test, I know it fails, if it fails treat the test as a success and move on. If it succeeds, report the test as a failure.
This would probably be rather simple to implement using an additional attribute to the test, something like:
<test name="Failed test" assert="fails">
...
</test>
and the default value of assert could be success, so we have backward compatibility. But if we were to extend it slightly, like so:
attribute-value = method name
equals = assertOutParamEquals, assertUpdateCountEquals, assertColumnsEquals, ...
not-equals = !assertEquals
outparam-equals = assertOutParamEquals
column-equals = assertColumnEquals
... etc.
so each value of the attribute @assert is linked to a method name which would live in a particular file, say Assertions.java. The first entry refers to an assertion chain, so the assertion "equals" would be equal if all the underlying assertion methods returned true. The second assertion "not-equals" is true if "equals" is not true. The third and fourth refer to individual assertion methods, which are available to the caller. So if the caller only wanted to test that the update counts were equal, then he can only put that in. The caller can also build assertion chains by specifying a comma-separated list of individual assertions.
If you have a better or different way of doing this, I would like to know, or maybe ideas for extensions that I havent thought of.
Thanks
Sujit
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no clean way to automate failure testing in SQLUnit. By that I mean, that if I want to incorporate scenarios that end in failure, then I have no way to tell SQLUnit:
here is a test, I know it fails, if it fails treat the test as a success and move on. If it succeeds, report the test as a failure.
This would probably be rather simple to implement using an additional attribute to the test, something like:
<test name="Failed test" assert="fails">
...
</test>
and the default value of assert could be success, so we have backward compatibility. But if we were to extend it slightly, like so:
attribute-value = method name
equals = assertOutParamEquals, assertUpdateCountEquals, assertColumnsEquals, ...
not-equals = !assertEquals
outparam-equals = assertOutParamEquals
column-equals = assertColumnEquals
... etc.
so each value of the attribute @assert is linked to a method name which would live in a particular file, say Assertions.java. The first entry refers to an assertion chain, so the assertion "equals" would be equal if all the underlying assertion methods returned true. The second assertion "not-equals" is true if "equals" is not true. The third and fourth refer to individual assertion methods, which are available to the caller. So if the caller only wanted to test that the update counts were equal, then he can only put that in. The caller can also build assertion chains by specifying a comma-separated list of individual assertions.
If you have a better or different way of doing this, I would like to know, or maybe ideas for extensions that I havent thought of.
Thanks
Sujit