简体   繁体   中英

Ignore attributes' order when comparing xml with ApprovalTests

I am trying to Approvals.Verify xml but problem is attributes' order. In few elements they are in different order in my computerand Jenkins. From other question I found to change order of properties in class. That kinda worked: it changed attributes' order but it now Jenkins' order is what it used to be in my computer and vice versa. So no help from changed properties' order in class.

Is there any way to use ApprovalTests to ignore xml attributes' order? Or how can I say exact order for attributes in xml serialization? Or other hints?

According to the XML Standard Section 3.1, the order of attribute specifications in a start-tag or empty-element tag is not significant. So a change in XML attribute ought not trigger a unit test failure.

And, from the reference source , it appears that the method XmlApprovals.VerifyOrderedXml() normalizes the order of attributes before validation by internally calling XmlUtils.FormatXmlWithOrderedAttributes() which recursively sorts all attributes. Thus this method should meet your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM