我正在研究这个优秀的教程,但最后我的第一个测试没有通过,因为我可以清楚地看到我正在创建两个不同的数组(和指针),并试图将它们相互比较。
现在,我所看到的教程省略了我添加的几行代码,这也是我看到问题的地方,但没有这些行,代码甚至不会运行粗糙。
我的所有其他测试方法都与示例相同,除了我创建了以下几行的此方法 - 否则在运行测试时不会发生任何事情。
Public Sub Run(ByVal dataService As IDataService, ByVal wsService As IWorksheetService)
Dim data As Variant 'Added this line
data = dataService.GetSomeTable 'Added this line
Call wsService.WriteAllData(data) 'Added this line
End Sub
在这里我可以看到代码向南...
'@TestMethod
Public Sub WorksheetServiceWorksOffDataFromDataService()
'Arrange
Dim dataServiceStub As MyDataServiceStub
Set dataServiceStub = New MyDataServiceStub
Dim expected As LongLong
expected = VarPtr(dataServiceStub.GetSomeTable) 'expected creates an Array
Dim wsServiceStub As MyWorksheetServiceStub
Set wsServiceStub = New MyWorksheetServiceStub
'Act
With New MyTestableMacro
.Run dataServiceStub, wsServiceStub 'here we create a second array
End With
Dim actual As LongLong
actual = wsServiceStub.WrittenArrayPointer 'here we point to the address of the second array
'Assert
Assert.AreEqual expected, actual ' this test fails cause it points to two different addresses
End Sub
由于 64 位上的数字对于 Long 来说太长了,我不得不将类型从 Long 更改为教程中指向 LongLong 的数组指针。LongPtr 也有效