RhinoMocks - 模拟受保护的虚拟成员

发布于 2024-09-06 02:56:20 字数 94 浏览 2 评论 0原文

据我所知,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女中豪杰 2024-09-13 02:56:20

如果我想模拟受保护的成员,我通常会跳过 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.

将军与妓 2024-09-13 02:56:20

据我所知,RM 应该嘲笑
任何可以通过a访问的东西
派生类。

不。我们的想法是,您应该能够模拟被测类的依赖关系的行为。此处使用的“依赖项”一词与依赖项注入

在测试驱动开发中,通常优先于组合而不是继承。依赖关系通常隐藏在接口后面。

我的理解是 RM 不
支持模拟受保护的虚拟
成员。

这是正确的。在设置行为时,有两种简洁且类型安全的方法可以指定您正在讨论的类成员:通过以记录模式调用成员,或使用 lambda 表达式。 Rhino Mocks 两者都支持,但两者都不适用于受保护的成员。

As far as I know, RM should mock
anything that can be accessed by a
derived class.

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.

My understanding is that RM does not
support mocking protected virtual
members.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文