我有一个比较两个字符串的 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());
}
}
我org.junit.ComparisonFailure
在第二次测试中遇到了异常。但是,IntelliJ 显示的内容是相同的。我错过了什么?
编辑:在预期字符串的末尾添加回 \n 。