Posts Tagged ‘ApprovalTests’

Unit tests and comparing long strings or objects

June 16th, 2014

I have tested and really liked ApprovalTests with more info in the blog by Llewellyn Falco.

When the unit test fails, and only if it fails, a comparer of choice pops up (think Winmerge or similar).

Say you have a long string where, somewhere, the testing framework reports a diff; you have to sift through the whole 1000 characters and compare by eye. If the discrepancy is a space/tab or apostrof/accent you might have a very hard time to spot the diff.
Or say you have an object with 10 or so properties. The unit testing framework reports a diff and you have to iterate through the properties and maybe sub properties for two objects. Tedious and not fun even the first time. The third of 10th time you really should be looking for a better solution.

I started writing my own but dropped that project in a second for AprovalTests.

Another, not as polished, solution is from SHaack. It is an extension to a unit test framework. You have to implement your own if you have another unit testing framework of choice.