AssertEquals(String, String) ComparisonFailure when contents are identical

前端 未结 2 542
刺人心
刺人心 2020-12-18 21:33

I\'m facing the following scenario:

I have an app that spits everything out to the STDOUT (simple company test) and I\'m trying to JUnit this.

My problem is,

相关标签:
2条回答
  • 2020-12-18 21:54

    The visible characters are identical, but the non-printable characters are not.

    You are comparing expected output containing CRLF (\r\n) to actual output with just LF (\n). You can see that in IntelliJ above the right-hand side of both text areas.

    Simple solution is to replace the \n's in your string with \r\n. Or remove \r from the other.


    It is also worth noting that the parameter ordering is actually (Object expected, Object actual), so the outContent should go second since that is the "actual" output.

    0 讨论(0)
  • 2020-12-18 21:59

    You can use AssertJ "isEqualToNormalizingNewline" as in:

    import static org.assertj.core.api.Assertions.assertThat;
    
    ...
    
    @Test
    public void ingoreLineEndingCharacterTest() {
        assertThat("First Line\nSecond Line\n").isEqualToNormalizingNewlines("First Line\r\nSecond Line\r\n");
    }
    
    0 讨论(0)
提交回复
热议问题