在 NBehave 中使用具有多个场景的 Mock
我使用 NBehave 来写出我的故事,并使用 Rhino Mocks 来模拟被测系统的依赖关系。
但是,当从一个场景转移到下一个场景时,我在重置模拟依赖项中的预期行为时遇到问题。
我只想断言我的存储库上的 save 方法在两种情况下被调用:
dependancyRepository.AssertWasCalled( ear =>
ear.Save(
Arg<IDependancy>.Is.Equal(dependency)
)
)
但这在每种情况下都被调用,并且在我的第二种情况下失败,因为 Rhino Mocks 期望它只被调用一次。 我不想被迫使用明确的期望,但看起来我也会有。
有一些 NBehave 与 Rhino Mocks 的示例,但我无法提供具有多种场景的示例。 有一些具有 NBehave 和多个场景,但没有模拟。
还有其他人遇到这个问题吗?
干杯
I'm using NBehave to write out my stories and using Rhino Mocks to mock out dependencies of the System(s) Under Test.
However I'm having a problem resetting expected behaviour in my mock dependencies when moving from one scenario to the next.
I only want to assert that the save method on my repository was called in two scenarios:
dependancyRepository.AssertWasCalled( ear =>
ear.Save(
Arg<IDependancy>.Is.Equal(dependency)
)
)
But this is being called in each scenario and fails in my second scenario because the Rhino Mocks expects it be called just once. I don't want to be forced to use an explicit expections but it kinda looks like I'll have too.
There are a few examples out there of NBehave with Rhino Mocks but I can't one that has multiple scenarios. And there are a few with NBehave and multiple Scenarios but no mocks.
Anybody else run into this issue?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在相关场景的 then 子句中进行 AssertWasCalled 调用,而不是在任何其他场景中进行调用。
Make the AssertWasCalled call during your Then clause of the relevant scenario, and not in any others.
如果您不想断言 .Save(...) 在每个场景中都被调用,则不要为每个场景设置该期望,而仅针对您期望调用它的场景进行设置。
如果这不能回答您的问题,请提供更多信息来澄清您的问题; 目前尚不清楚你想做什么。
If you don't want want to assert that .Save(...) was called in each scenario, then don't set up that expectation for each scenario, set it up only for the scenarios where you expect it to be called.
If this doesn't answer your question, please clarify your question with more information; it's unclear what you're trying to do.