RhinoMocks/AssertWasCalled:验证参数长度?
我的 MSpec 测试将断言使用(至少)给定长度的参数调用给定方法。
尽管参数(在运行时)的长度为 534,但此语法使断言失败:
_foo.AssertWasCalled(x => x.Write(Arg.Text.Like(".{512,}")));
ExpectationViolationException: IFoo.Write(如“.{512,}”);预期 #1,实际 #0。
我对 Like() 的模式做错了什么?
My MSpec test will assert that a given method was called with an argument of (at least) a given length.
This syntax is failing the assertion, despite the argument (at runtime) having a length of 534:
_foo.AssertWasCalled(x => x.Write(Arg.Text.Like(".{512,}")));
ExpectationViolationException: IFoo.Write(like ".{512,}"); Expected #1, Actual #0.
What have I done wrong with Like()'s pattern?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许与您使用的RhinoMocks版本有关?我正在使用 RhinoMocks 版本 3.5.0.1337,Like 可以正确检测长度。
测试
如果我使用 .Expect() 而不是 .AssertWasCalled() 顺便说一下,测试也会通过。
如果您通过了这些测试,并且您确定参数的长度,则通过将测试更改为
编辑来验证是否正在调用 Write:
RhinoMocks 版本 3.6.0.0 也通过了这些测试
Perhaps it is related to the version of RhinoMocks you are using? I'm using RhinoMocks version 3.5.0.1337 and Like detects the length correctly.
tests
The tests also pass if I use .Expect() instead of .AssertWasCalled() by the way.
If these tests pass for you and you are certain about the length of the argument then verify that Write is being called by changing the test to
edit:
The tests also pass with RhinoMocks version 3.6.0.0
为什么不直接测试争论的长度
一般在Rhino模拟中当你得到“预期#1,实际#0”时。这意味着 Equals 存在问题,例如没有在对象上实现 equals。
Why not test the length of the arguement directly
Generally in Rhino mocks when you get "Expected #1, Actual #0." it means that there is a problem with Equals, for example not having implemented equals on an object.