尝试将 XML 输入与 XML 输出进行比较的 JUnit 类失败。
TestCase.assertEquals(msg, expected, actual);
有什么方法可以比较来自 JUnit 的 XML i/p 和 o/p 吗?
最佳答案
你可以看看XMLUnit .这允许您比较两个 XML 文档。来自文档:
XMLUnit enables JUnit-style assertions to be made about the content and structure of XML. It is an open source project hosted at http://xmlunit.sourceforge.net/ that grew out of a need to test a system that generated and received custom XML messages. The problem that we faced was how to verify that the system generated the correct message from a known set of inputs. Obviously we could use a DTD or a schema to validate the message output, but this approach wouldn't allow us to distinguish between valid XML with correct content (e.g. element bar) and valid XML with incorrect content (e.g. element baz). What we really wanted was an assertXMLEqual() method, so we could compare the message that we expected the system to generate and the message that the system actually generated.
关于xml - 比较 JUnit 中的 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8033820/