I'm writing unit tests for a code generator, and most of my tests compare output that spans several lines against some golden output. Currently, I'm comparing outputs with Assert.AreEqual(string, string)
which displays the context around the first difference.
Unfortunately, this isn't very helpful. Ideally, I'd like to get a diff of the outputs. What is the best way of doing this? My current plan is to write the generated code to a file and call the executable referenced by the DIFFTOOL
env var (else diff.exe
from PATH
, else the default NUnit behavior) and call Assert.Fail()
with an appropriate message.
You can eliminate the clipping of long strings by specifying .NoClip
as a modifier of an EqualConstraint
. This requires you to switch from the legacy Assert.AreEqual
to use the constraint model of assertion:
C#
Assert.That(actual, Is.EqualTo(expected).NoClip);
This will give you the full value of both strings, but may be hard to read without reformatting.
We have long had an interest in improving the display of differences between two long strings. Come and do a PR! :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With