Diffs in Unit Tests

Published on Monday, August 25, 2014

Photo by Jan Loyde Cabrera on Unsplash

While working on my refactorable settings code extension, I needed to verify that the output of the tool matched some sample output from the original settings code generation tool. Unfortunately, Assert.AreEqual on two really long strings of generated code doesn't give you a whole lot of helpful information about exactly which characters don't match (especially if non-printing characters are the problem). A little googling turned up an amazingly useful solution from Phil Haacked - a set of classes which display a character-by-character diff of the two strings.

I actually ended up using this slightly modified version by Sina Iravanian. If no one else has put this into a nuget package by the next time I need it, I'm going to have to do it myself; it's too incredibly useful to only be available for cut-and-paste.