Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 XMLUnit 2.x 中,我可以忽略实际(“控制”)XML 中不存在于我的测试(“预期”)XML 中的所有元素吗?
例子:
实际的:
<a>123</a> <b>456</b> <c>789</c>
测试:
<b>456</b> <c>xxx</c>
我想检测差异<c>但完全忽略<a>标签,因为它不存在于测试 XML 中。
<c>
<a>
我的想法是我有一个要比较的大 XML,但我只对元素的一个子集感兴趣,我不想给 XMLUnit 一个仍然很大的元素名称列表以忽略或不忽略。
您可以在所有和比较中使用自己的DifferenceEvaluator并返回ComparisonResult.SIMILAR(甚至)。EQUALCHILD_NODELIST_LENGTHCHILD_LOOKUP
DifferenceEvaluator
ComparisonResult.SIMILAR
EQUAL
CHILD_NODELIST_LENGTH
CHILD_LOOKUP
如果您只想忽略测试文档中添加的元素(而不是忽略与方向无关的另一侧不存在的所有元素),那么您应该仅CHILD_NODELIST_LENGTH在控制长度大于测试长度且CHILD_LOOKUP节点缺失的 s时降级在测试方面。