0

I have a stored procedure that I am trying test for the proper generation of an output parameter. I experimented with tsqlt.ExpectException, but that did not work. I instead am trying tsqlt.AssertEqualsTable.

    CREATE TABLE #actual (msg NVARCHAR(MAX));
CREATE TABLE #expected (msg NVARCHAR(MAX));
INSERT #expected (msg) VALUES (N'Location w1005 has LPNs that were produced against a different production order than 1')
--EXEC tSQLt.ExpectException @ExpectedMessage = N'Location 1 has LPNs that were produced agains a different production order than orderNumber';

EXEC dbo.wms_whse_check_location
    @command = @Command, @operLocationHasOtherLPN=@operLocationHasOtherLPN OUTPUT;  


INSERT #actual (msg) VALUES (@operLocationHasOtherLPN) 


EXEC tsqlt.AssertEqualsTable @Expected = '#expected', @actual = '#actual'

The test fails, and the output from tsqlt is:

Unexpected/missing resultset rows! |m|msg | +---+--------------------------------------------------------------------------------------+ |< |Location w1005 has LPNs that were produced against a different production order than 1| |> |Location w1005 has LPNs that were produced against a different production order than l|

It may be hard to see in the above snip, but the < (expected) row is identical to the > (actual) row -- tsqlt finds a difference that in fact doesn't exist. I'm not choosing the correct method it seems.

Has anyone written tests to check ouput parameters? What is the appropriate method? Thanks

p.s. Apologies for the messy formatting. I'm not a regular poster.

David
  • 13
  • 2

2 Answers2

0

tSQLt.AssertEqualsString is in fact the appropriate test. I don't know where I went wrong, but when I concatenated the appropriate expected message in code (as opposed to typing it out), then ran the test, it succeeded.

David
  • 13
  • 2
0

Use tSQLt.AssertEqualsString, as you found out already.

Also, your two strings are not identical. The one ends in “1”, the other one doesn’t.

Sebastian Meine
  • 11,260
  • 29
  • 41