相关疑难解决方法(0)

Rhino Mocks存根和模拟只适用于接口?

Rhino Mocks存根和模拟只对接口有用,而不是具体的类吗?我花了很多时间试图让这段代码工作.我没想到存根的pubSubClient总是从类中调用Send方法.该方法有一些依赖项并抛出异常.

[Test]
public void Test01()
{
    PubSubMessage psm = new PubSubMessage(); 
    var pubSubClient = MockRepository.GenerateStub<PubSubClient>();
    pubSubClient.Stub(x => x.Send(psm)).IgnoreArguments().Return(null);
    // actual PubSubClient Send method throws exception
    // the rest of the test is skipped...
}
Run Code Online (Sandbox Code Playgroud)

但是,当我提取界面并使用IPubSubClient运行相同的测试时,它似乎按预期工作.

这是否意味着我必须为我想要使用Rhino模拟/存根的每个类提取接口?或者我在技术上或概念上遗漏了什么?

更新:好的,我似乎弄清楚了我缺少的部分: Rhino Mocks无法拦截对非虚方法的调用.所以,我想我要么使用接口,要么在具体类虚拟上使用每个方法.如果还有其他选择,请纠正我.

.net unit-testing rhino-mocks mocking stubbing

21
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

mocking ×1

rhino-mocks ×1

stubbing ×1

unit-testing ×1