【发布时间】:2020-07-15 17:07:25
【问题描述】:
我用 NSubstitute 创建了一个 Substitute
var mockService = Substitute.For<IService>();
仅当函数参数为 integer 时,我才能成功替换 IService 中的函数。在其他情况下,当我的代码调用 IService 的函数时,我会收到结果 null/0/byte[0]。
MyResponse Request(byte[] request, MyAddress target); //null
int test(int t); //expected result
int SimpleRequest(byte[] request, MyAddress target); /0
MyResponse SimpleParam(int i); //expected result
byte[] testbyte(byte[] t); //byte[0]
byte[] testintbyte(int t); //expected result
int testbyteint(byte[] t); //0
当我在测试中证明这个函数时,它们会按预期返回值:
Assert.Equal(mockService.Request(request, target), MyResponse);//true
为什么我在 NSubstitute 中只能使用整数作为函数参数?
【问题讨论】:
-
你没有展示你是如何替换函数的。也许发布更多您的测试方法。另请参阅nsubstitute.github.io/help/set-return-value,了解有关如何在替代类上设置返回值的基础知识。
标签: parameters null return nsubstitute