unit testing - Rhino Mocks: Minimal times to call seems not to work -


im using rhino-mocks 3.6 mocking framework in unit tests , have problem repeat.times():

i want verify method on mocked object called 3 times. according docs should use repeat.times(3) or repeat.times(3, 3).

but observe verifying at least 3 calls, when call method 4 times, test still passes. fails when calling method 2 times.

here code. there wrong it?

        mockrepository mocks = new mockrepository();         ijobserviceevent mockedjse;         using (mocks.record())         {             mockedjse = mocks.dynamicmock<ijobserviceevent>();             expect.call(() => mockedjse.transactionlistchanged(null))                 .repeat.times(3);         }          using (mocks.playback())         {             mockedjse.transactionlistchanged(null);             mockedjse.transactionlistchanged(null);             mockedjse.transactionlistchanged(null);             mockedjse.transactionlistchanged(null);         } 

you need use strictmock. dynamicmock allow methods calls aren't expected. call method expected 3 times (which happens). when happens fourth time, it's not error since defined dynamicmock (unexpected calls allowed).

however, in long run, using strickmock can maintenance headache since test knows how object written (since have mock/stub every possible call may made).

i recommend aaa (arrange, act, assert) syntax unit tests. test above written using stub, still enforce 3-limit call on method:

ijobserviceevent mockedjse = mockrepository.generatestub<ijobserviceevent>();  mockedjse.transactionlistchanged(null); mockedjse.transactionlistchanged(null); mockedjse.transactionlistchanged(null); mockedjse.transactionlistchanged(null);  mockedjse.assertwascalled(s => s.transactionlistchanged(null), o => o.repeat.times(3, 3)); 

update

to make sure calls args made (although think strict mock can become maintenance headache), use arg constraints option 3 times make sure calls made. have final "assertwascalled" ignores arguments , make sure called 3 times:

mockedjse.assertwascalled(s => s.transactionlistchanged(null), o => o.ignorearguments().repeat.times(3, 3)); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -