简体   繁体   中英

Identical Content But JUnit Test Fails(IntelliJ)

I have a JUnit Test that compares two strings:

@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());
    }
}

I'm getting a org.junit.ComparisonFailure exception on the second test. However, IntelliJ shows contents are identical. What am I missing?

EDIT: Added back the \\n at the end of the expected string.

在此输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM