Rhino Mocks:AssertNotCalled(加载时除外)
我有一个依赖项,当创建我正在测试的对象时会调用该依赖项。但是,此后决不应该调用它。我将如何编写这样的测试?
我只想将这一行作为我的测试(因为我试图遵循 AAA 测试编写风格)。但是,此断言将失败,因为在设置期间调用了 Publish 方法。
Notifier.AssertWasNotCalled(Sub(n) n.Publish(Arg(Of Message).Is.Anything))
有没有办法“重置”对我模拟的依赖项的调用?
注意:我可以对其进行设置,以便在初始化后检查 Message
参数上的属性以获得我期望的值,但这使我的测试更加脆弱/脆弱,并且我如果可能的话想避免它。
_notifier.AssertWasNotCalled(
Sub(n) n.Publish(Arg(Of Message).Matches(Function(m) m.property = "yo!")))
I have a dependency that gets called when the object I'm testing is created. However, it should never be called after that. How would I write such a test?
I'd like just this line as my test (since I'm trying to follow the AAA style of test writing). However, this assertion will fail since the Publish
method was called during setup.
Notifier.AssertWasNotCalled(Sub(n) n.Publish(Arg(Of Message).Is.Anything))
Is there a way to "reset" the calls on the dependency I've mocked?
Note: I can set it up so that I check the property on the Message
argument for a value I expect after initialization, but that makes my test more fragile/brittle and I'd like to avoid it if possible.
_notifier.AssertWasNotCalled(
Sub(n) n.Publish(Arg(Of Message).Matches(Function(m) m.property = "yo!")))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将这样做:
因为这将确保它仅被调用一次,这将由您所指示的设置代码触发。
Here is how I would do it:
As this would make sure it is called once only, which would be triggered by your setup code as you have indicated.