I have a test that calls a stored procedure. I expect the stored procedure to reject the input supplied, with a raiserror. The relevant part of my tSQLt test is:
EXEC tSQLt.ExpectException @ExpectedMessagePattern = '%more than one subcategory%';
EXEC usp_add_rfx_rfx lots, of, parameters, here
The test result from tSQLt depends on the severity in the raiserror in the usp_add_rfx_rfx sp.
If the severity is 12 or more, the test fails with this message:
[test_RFX_configuration].[test_multiple_categories_and_lots] failed: (Error) Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0.[16,2]{test_multiple_categories_and_lots,0} (There was also a ROLLBACK ERROR --> The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.{Private_RunTest,149})
If the severity is less, the test fails like this:
[test_RFX_configuration].[test_multiple_categories_and_lots] failed: (Failure) Expected an error to be raised.
I've googled the issue and tried a number of things I found - using TRY-CATCH etc but no joy. Any ideas?