尽管所有参数都匹配,为什么函数 Stub 可能不会被调用? [英] Why might a function Stub not get called in spite of all it's arguments matching?

查看:26
本文介绍了尽管所有参数都匹配,为什么函数 Stub 可能不会被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 2012 中的 Visual Basic .NET 中编写测试.在一个特定的存根中,我确定所有参数都匹配,但只有在我添加 IgnoreArguments 时它才会被执行,但由于我需要为相同的方法使用其他类似的存根,因此在生产环境中是不可接受的.

I'm writing a test in Visual Basic .NET in Visual Studio 2012. In a particular Stub I'm sure all the arguments match but yet it only gets executed if I add IgnoreArguments to it, but since I need to have other similar stubs for that same method this is not acceptable for production.

我无法发布代码示例(好吧,我可以,但它需要非常大才能有用).但是,如果我告诉您这是以下形式的请求,可能就足够了:

I can't post a code sample (well, I could, but it would need to be really big in order to be useful). But it might suffice if I tell you that it's a request in the shape of:

Dim request As IMyRequest = MyService.CreateRequest(obj1, obj2, list1, 
    int1, int2, bool1, bool2, bool3, string1, bool4, int3)

我的存根看起来像:

_myService.Stub(Function(x) x.CreateRequest(obj1, obj2, list1, 
    int1, int2, bool1, bool2, bool3, string1, 
    bool4, int3)).IgnoreArguments.Return(myRequest)

_myService 是在 TestInitialize 方法中定义的模拟,如下所示:

And _myService is a mock defined in the TestInitialize method like so:

_myService= Mock.Get(Of IMyService)()

我已经检查过并且所有值都匹配.还有另一个非常相似的测试,它有一个非常相似的调用(它在没有 IgnoreArguments 子句的情况下完美地工作),我用作示例,所以我不知道为什么这不起作用.

I've checked and all the values match. There's also another very similar test with a very similar call (which works perfectly without the IgnoreArguments clause) that I've used as sample, so I'm at a loss as to why this isn't working.

问:我很抱歉问这么含糊的问题,但有人能想到我可能遗漏的任何检查吗?

Q: I'm sorry to ask such a vague question, but can anyone think of anything I might be missing to check?

我会澄清任何没有意义的.感谢阅读.

I'll clarify whatever doesn't make sense. Thanks for the read.

哎呀,结果(在又一双眼睛看了一眼代码之后)确实有一个参数的类型是关闭的.是的,类名太相似了我不知道如何关闭它,所以就让它死吧.感谢并抱歉占用了您的时间.

whelp, it turned out (after yet another pair of eyes glanced at the code) that indeed the type of one of the parameters was off. yay for disgustingly similar class names I'm not sure how to close this, so just let it die. Thanks and sorry for robbing you of your time.

推荐答案

我假设您在此处模拟服务以进行测试.存根上的对象相等可能是导致它不被调用的原因.没有更多信息很难说,但这是我首先要看的.

I assume you are mocking the service here for your test. Object equality on the stub is probably what is causing it to not get called. Without more information it is hard to say but that is the first thing I would look at.

这篇关于尽管所有参数都匹配,为什么函数 Stub 可能不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆