Using JUnit assertEquals(), I am comparing strings which may differ in whitespace/control characters.
In particular, '\r\n' vs. '\n'.
When the strings differ in this way the error output from assertEquals() is difficult to interpret for a few reasons.
- They are whitespace characters and are not suitable for visual inspection
- The \r character causes output to be overwritten.
This example shows how you'd normally test a string if you wouldn't have any special chars within */
@Test
public void testIfTheCarriageReturned()
{
final String expected = "we're taking\r\n the hobbits\r\n to Isengard!";
final String actual = "we're taking\n the hobbits\n to Isengard!";
assertEquals(expected, actual);
}
This example correctly determines that the strings differ but the output from JUnit does not make it clear how they differ (whitespace not being treated in any special way).
Is there a way to cause JUnit to produce more suitable output?