RhinoMocks - 模拟受保护的虚拟成员
据我所知,RM 应该模拟任何可以被派生类访问的东西。既然受保护的虚拟成员可以从子类访问,那么它不应该是可模拟的吗?
我的理解是RM不支持模拟受保护的虚拟成员。
As far as I know, RM should mock anything that can be accessed by a derived class. Since a protected virtual member is accessible from a subclass, shouldn't it be mockable?
My understanding is that RM does not support mocking protected virtual members.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我想模拟受保护的成员,我通常会跳过 Rhino Mocks 并使用我自己的假实现对其进行子类化。
If I want to mock a protected member I usually skip over Rhino Mocks and just subclass it with my own fake implementation.
不。我们的想法是,您应该能够模拟被测类的依赖关系的行为。此处使用的“依赖项”一词与依赖项注入。
在测试驱动开发中,通常优先于组合而不是继承。依赖关系通常隐藏在接口后面。
这是正确的。在设置行为时,有两种简洁且类型安全的方法可以指定您正在讨论的类成员:通过以记录模式调用成员,或使用 lambda 表达式。 Rhino Mocks 两者都支持,但两者都不适用于受保护的成员。
No. The idea is that you should be able to mock the behavior of dependencies of the class under test. The word dependencies is used here in the same sense as in dependency injection.
In test driven development, one typically favors composition over inheritance. Dependencies are typically hidden behind interfaces.
That's correct. There are two concise and type-safe ways to specify which class member you're talking about when setting up behavior: by calling the member in a record mode, or with a lambda expression. Rhino Mocks supports both, but neither can work for protected members.