EXEC tSQLt.AssertEqualsTable 'expected', 'actual';
I am comparing expected vs actual tables. This table has 100k plus records and if 80k records match 20k records don't match then tsqlt will paint like below each failed row and it takes hours of time to complete. How can avoid tsqlt displaying the unmatched records in the output?
These tables would result in the following failure message:
failed: unexpected/missing resultset rows!
|_m_|col1|col2|col3|
+---+----+----+----+
|< |2 |B |b |
|< |3 |C |c |
|= |1 |A |a |
|> |3 |X |c |
100,000 rows is far in excess of what is reasonably required for a unit test.
You should be able to test all scenarios with considerably fewer rows than that.
But if tSQLt.AssertEqualsTable
doesn't meet your needs as it prints out potentially huge strings you can just do your own checks and assertions - e.g. as below (assumes Actual
and Expected
have the same column schema definitions).
DECLARE @expectedRows INT,
@actualRows INT,
@expectedChk INT,
@actualChk INT;
SELECT @expectedRows = COUNT(*),
@expectedChk = CHECKSUM_AGG(binary_checksum(*))
FROM Expected
SELECT @actualRows = COUNT(*),
@actualChk = CHECKSUM_AGG(binary_checksum(*))
FROM Actual
EXEC tSQLt.AssertEquals
@expectedRows,
@actualRows,
'Mismatched rowcount between expected and actual'
EXEC tSQLt.AssertEquals
@expectedChk,
@actualChk,
'Mismatched checksum between expected and actual'
--Row count the same and checksum the same. Do more rigorous check.
IF EXISTS(SELECT *
FROM (SELECT 1 AS [🗑️], *
FROM Expected) E
FULL JOIN (SELECT 1 AS [🗑️], *
FROM Actual) A
ON EXISTS(SELECT A.*
INTERSECT
SELECT E.*)
WHERE A.[🗑️] IS NULL
OR E.[🗑️] IS NULL)
EXEC tSQLt.Fail
'Mismatched row content between expected and actual';