加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.NET中的问题单元测试

发布时间:2020-12-17 07:21:11 所属栏目:百科 来源:网络整理
导读:我有以下代码: TestMethod() _Public Sub GetDirectoryEntryTest() Dim path As String = runner.getLDAPPath() Dim expected As DirectoryEntry = runner.GetDirectoryEntry() Dim actual As DirectoryEntry actual = LDAPBase.GetDirectoryEntry(path) As
我有以下代码:

<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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读