Search code examples
tsqlt

tSQLt - How to output a custom failure or success message?


We are using the tSQLt framework and have the below code in the test.

IF @count>0
    EXEC tsqlt.fail;
else EXEC tSQLt.AssertEquals 1,1;

I am interested to know how we can display a custom test success or failure message when this test gets executed?


Solution

  • tSQLt.fail takes up to 10 parameters that all get concatenated into a custom failure message.

    You also do not need the call to tSQLt.AssertEquals as it, in your case, literally does nothing.

    BTW, asserting a count is in almost all cases a bad idea, as it does not really tell you anything about the result. If you get the correct count back, you could still have wrong data. And if you get the incorrect count, you don't have any additional info on what went wrong.

    Have a look at tSQLt.AssertEqualsTable or tSQLt.AssertEmptyTable instead.