我正在做一个 Junit 测试,其中方法的输出是 XML 格式的字符串。我不确定为什么字符串比较失败
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"<RATE>1.0</RATE>", XMLUtil.formatXML(TEST_XML));
Actaul response from the method :
<?xml version="1.0" encoding="ISO-8859-1"?>
<RATE>1.0</RATE>
错误 :
junit.framework.ComparisonFailure: expected:<...oding="ISO-8859-1"?>[
<RATE>1.0</RATE>]> but was:<...oding="ISO-8859-1"?>[
<RATE>1.0</RATE>
]>
]
编辑 即使最后添加新行也无济于事:
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"<RATE>1.0</RATE>\n", XMLUtil.formatXML(TEST_XML));
junit.framework.ComparisonFailure: expected:<...oding="ISO-8859-1"?>[
<RATE>1.0</RATE>]
> but was:<...oding="ISO-8859-1"?>[
<RATE>1.0</RATE>
]
>