Asserting that a method is called exactly one time

后端 未结 7 1329
无人共我
无人共我 2021-02-05 03:16

I want to assert that a method is called exactly one time. I\'m using RhinoMocks 3.5.

Here\'s what I thought would work:



        
7条回答
  •  遥遥无期
    2021-02-05 03:55

    Having a feature called "Exactly" would be handy to write tests on code that might otherwise get into an infinite loop. I would love to write a test such that the second call to a method would raise an exception.

    Some libraries for python allow you to sequence expectations, so the first returns false and the second raises an exception.

    Rhino won't do that. A partial mock with .Once will intercept the first call, and the rest will be passed on to the original method. So that sucks, but it's true.

    You'll have to create a hand-mock. Derive a "testable" class, and give it the ability to raise after the first call.

提交回复
热议问题