相同的内容但JUnit测试失败(IntelliJ)

Raj*_*ami 3 java junit intellij-idea system-rules

我有一个比较两个字符串的JUnit测试:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CDPlayerConfig.class)
public class CDPlayerTest {

    @Rule
    public final SystemOutRule log = new SystemOutRule().enableLog();

    @Autowired
    private CompactDisc cd;

    @Autowired
    private MediaPlayer player;

    @Test
    public void cdShouldNotBeNull() {
        assertNotNull(cd);
    }

    @Test
    public void play() {
        player.play();
        assertEquals("Playing title Sgt. Pepper's Lonely Hearts Club Band by artist The Beatles\n",
                log.getLog());
    }
}
Run Code Online (Sandbox Code Playgroud)

org.junit.ComparisonFailure在第二次测试时遇到异常.但是,IntelliJ显示的内容是相同的.我错过了什么?

编辑:添加回预期字符串末尾的\n.

在此输入图像描述

Mar*_*zak 5

你有不同的终点线标志(LF vs CRLF)


Cra*_*aig 5

尝试添加 alog.getLog().trim()并从预期字符串的末尾删除 \n 。