New DUnitLite feature: String context

When you’re comparing long strings, DUnitLite 0.2 (download) now shows just the context — the first character that’s actually different, plus 30 characters before and after — instead of the entire string. If there’s only a small difference buried in a really long string, this makes the difference much easier to spot.

Specify.That(Query.Sql.Text, Should.Equal(ExpectedSql));

Expected: ...'.TicketID = Tickets.ID'#13#10'WHERE Component = 42 AND Status = 1 A'...
but was: ...'.TicketID = Tickets.ID'#13#10'WHERE Tickets.Component = 42 AND Tick'...

Ellipses (...) are added at the beginning and/or end to show you when you’re seeing a portion of the value, instead of the whole string.

I’d like to do like NUnit does, and show another line with a little arrow ^ pointing to the first character that’s different. Unfortunately, DUnit’s test-failure output isn’t shown in a fixed-width font, so I wouldn’t have much way to get it to line up.

Download DUnitLite 0.2 and give it a spin, and let me know how this feature works for you. I expect it to take some tuning and tweaking before it works reasonably well in most circumstances, and there’s no better way to know what needs tweaking than to use it in the field.

Leave a Reply

Your email address will not be published. Required fields are marked *