微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB.NET中的问题单元测试

我有以下代码

<TestMethod()> _
Public Sub GetDirectoryEntrytest()
    Dim path As String = runner.getLDAPPath()
    Dim expected As DirectoryEntry = runner.GetDirectoryEntry()
    Dim actual As DirectoryEntry
    actual = LDAPBase.GetDirectoryEntry(path)
    Assert.AreEqual(expected,actual)
End Sub

此单元测试失败. DirectoryEntry对象完全相同,但对不同对象的引用不同.我来自Java背景,你总是有.equals().

我能做什么才能正确评估并返回true,因为对于所有意图和目的,对象是相同的.有什么我可以像在Java中那样做并覆盖equals()吗?

解决方法

尝试将对象的路径与以下内容进行比较:

Assert.AreEqual(expected.Path,actual.Path)

这将比较底层路径(字符串类型)而不是对象引用.如果路径相同就足够了,你就不必重写任何东西.

编辑:

DirectoryEntry是一个从Object继承Equals的引用类型,因此:

Object.Equals Method开始:

The default implementation of Equals supports reference equality for reference types,and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐