NUnit - 断言检查所有属性是否相等?
Nunit 中是否内置了一个断言,可以检查两个对象之间的所有属性是否相同,而无需覆盖 Equals?
我目前正在使用反射来断言一对对象的每个单独属性。
Is there an assertion built into Nunit that checks all properties between 2 objects are the same, without me having to override Equals?
I'm currently using reflection to Assert each individual property for a pair of objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不相信有。
Assert.AreEqual 通过 Equals 比较非数字类型。
Assert.AreSame 检查它们是否引用同一个对象
I don't believe there is.
Assert.AreEqual compares non-numeric types by Equals.
Assert.AreSame checks if they refer to the same object
您可以使用名为 Should 的库编写与框架无关的断言。 它还具有非常好的流畅语法,如果您喜欢流畅的界面,可以使用它。 我有一篇与此相关的博客文章。
http://nileshgule.blogspot.com/ 2010/11/use-should-assertion-library-to-write.html
您可以使用两个对象和属性 ShouldBeEquivalentTo
You can write framework agnostic asserts using a library called Should. It also has a very nice fluent syntax which can be used if you like fluent interfaces. I had a blog post related to the same.
http://nileshgule.blogspot.com/2010/11/use-should-assertion-library-to-write.html
You can two objects and there properties with ShouldBeEquivalentTo
https://github.com/kbilsted/StatePrinter 专门用于将对象图转储为字符串表示形式编写简单的单元测试的目的。
给定
您可以以类型安全的方式,并使用自动完成Visual Studio 的包含或排除字段。
https://github.com/kbilsted/StatePrinter has been written specifically to dump object graphs to string representation with the aim of writing easy unit tests.
Given
You can in a type safe manner, and using auto-completion of visual studio include or exclude fields.