0

i wonder if someone is able to help me with my problem. I have to stub a method which is able to perform conditional mocking. In short, i like the stub function to return different objects of the same class depending on when it is called.

e.g.

  1. First call return Obj1
  2. Second call return Obj3
  3. Third call return Obj7

...

Does anyone know how to do this with NMock?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
zhengtonic
  • 720
  • 12
  • 25
  • I don't know the NMock framework but I won't be much different from the rest. I think in this case the work need to be done to setup the Stub/Mock will be allmost the same (if not more) than writing a simple Stub/Mock-Object yourself and I would go this road before brooding over this question for to long – Random Dev Aug 22 '11 at 06:43

1 Answers1

1

I think you'd be better off just writing the code to return an object based on the number of times it is called, rather than looking to the testing frameworks you're using for a solution to this issue.

So, if you had a "ObjectFactory" method of similar, you could keep a count of the number of times it's been called, and depending on the call number, return the appropriate object.

Matt Roberts
  • 26,371
  • 31
  • 103
  • 180