tSQLt-org / tSQLt

The official tSQLt repository. (Download at: http://tSQLt.org/downloads )
http://tSQLt.org
413 stars 102 forks source link

Mark differences in AssertEqualsTable result #161

Open mvomhau opened 2 years ago

mvomhau commented 2 years ago

to find the differences in the AssertEqualsTable result table it could be helpful to mark the different value with a special sign.

in this original result set are three differences, which are hard to find.

|ContraAccountType                   |ContraAccount                       |ReferenceNumber|Amount  |
+------------------------------------+------------------------------------+---------------+--------+
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 001      |105,0000|
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 001      |100,0000|
|00000000-0000-0000-0000-000000020094|00000044-0000-0000-0000-000000007990|FG-RG 002      |100,0000|
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 002      |100,0000|
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007991|FG-RG 003      |100,0000|
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 003      |100,0000|

It may be easier to spot the differences, when, for example, the left sign of a value pair is a ~ instead if a |

|ContraAccountType                   |ContraAccount                       |ReferenceNumber|Amount  |
+------------------------------------+------------------------------------+---------------+--------+
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 001      ~105,0000|
|00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 001      ~100,0000|
~00000000-0000-0000-0000-000000020094|00000044-0000-0000-0000-000000007990|FG-RG 002      |100,0000|
~00000000-0000-0000-0000-000000020093|00000044-0000-0000-0000-000000007990|FG-RG 002      |100,0000|
|00000000-0000-0000-0000-000000020093~00000044-0000-0000-0000-000000007991|FG-RG 003      |100,0000|
|00000000-0000-0000-0000-000000020093~00000044-0000-0000-0000-000000007990|FG-RG 003      |100,0000|

if the table structure is important, then this could also be a possibility and place a ~ between | and the values

+-------------------------------------+-------------------------------------+---------------+---------+
| 00000000-0000-0000-0000-000000020093| 00000044-0000-0000-0000-000000007990|FG-RG 001      |~105,0000|
| 00000000-0000-0000-0000-000000020093| 00000044-0000-0000-0000-000000007990|FG-RG 001      |~100,0000|
|~00000000-0000-0000-0000-000000020094| 00000044-0000-0000-0000-000000007990|FG-RG 002      | 100,0000|
|~00000000-0000-0000-0000-000000020093| 00000044-0000-0000-0000-000000007990|FG-RG 002      | 100,0000|
| 00000000-0000-0000-0000-000000020093|~00000044-0000-0000-0000-000000007991|FG-RG 003      | 100,0000|
| 00000000-0000-0000-0000-000000020093|~00000044-0000-0000-0000-000000007990|FG-RG 003      | 100,0000|
mbt1 commented 2 years ago

Without going too much into the technical details, the way tSQLt.AssertEqualsTable is written, attempting this will become very quickly too expensive computationally and sometimes straight out impossible. For example, if you expect one row with the values 'A', 'B' and get two rows 'A','C' and 'C','B'.

Currently, tSQLt is using the GROUP BY functionality to achieve this task, but with that is getting only information about the full row, not individual columns.

Do you maybe have suggestions on how to implement this while maintaining performance?

mvomhau commented 2 years ago

Possible solution:

(this solution is only possible with SQL Server 2012+)

mbt1 commented 1 year ago

This is a good idea and could be implemented going back before 2012, too, I believe (not with window functions). However, I am not sure this is providing an appropriate amount of value for the amount of work that would have to go into it. In my experience, if you are having trouble finding the differences, you might have too much going on in your test. If you test only a single piece of functionality, you rarely need to compare more than 3 or 4 columns.

I'll leave this open to see if others comment on it with a different opinion.