xml - 比较 JUnit 中的 XML 元素

标签 xml junit

尝试将 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/

相关文章:

java - Spring jdbcTemplate单​​元测试

java - JUnit 可以模拟 OutOfMemoryErrors 吗?

.net - 如何创建/更新可能存在或不存在的 XML 节点?

jquery - 在 XML 文档中使用 find() 和 first() 以及 replaceWith()

java - 保存屏幕旋转数据

android - 如何在 kotlin/android 中为对象类编写 junit 测试?

java - 无法解析我的测试类中的包 org.junit

python - 复制输入 xml 文件并用 Python 准确写入

c# - 这也太……hacky了吧? XML 到一个对象

java - JUnit 中的 "Unhandled exception type FileNotFoundException",尽管将其扔到普通类中?