jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recent commits broke verifyCount

Autoc0diq opened this issue · comments

Starting from 72c4011, a commit is causing verifyCount to incorrectly count new invocations.

[verifyCount(mockCache, times(1)) objectForKey:instanceOf(NSString.class)];
...
[verifyCount(mockCache, times(2)) objectForKey:instanceOf(NSString.class)];

Second verifyCount fails with "Wanted 2 times but was called 1 time"

That is actually expected. See #114.

Semantically speaking, every time you verify something was called, you want the verification to count only the matches since the last verification. For example, if I have:

  • method call
  • verify method was called once
  • other operations
  • verify method wasn't called due to other operations

This is what you want to express, so you write something like verifyCount(mock, times(0)). times(1) in this case doesn't represent your verification intent. Moreover, the previous behavior made your verifications dependent on each other, meaning you'd have to change all the subsequent verifications for a specific method should you had to change a verification in the beginning of your test method. This new mechanism, not only makes OCMockito more similar to other mocking frameworks in the market, but it also makes your verifications completely independent from each other.

Except it breaks all previously written tests. Where is this new behavior documented in the release.

On Jan 6, 2016, at 8:39 AM, gchaurais notifications@github.com wrote:

That is actually expected. See #114.

Semantically speaking, every time you verify something was called, you want the verification to count only the matches since the last verification. For example, if I have:

method call
verify method was called once
other operations
verify method wasn't called due to other operations
This is what you want to express, so you write something like verifyCount(mock, times(0)). times(1) in this case doesn't represent your verification intent. Moreover, the previous behavior made your verifications dependent on each other, meaning you'd have to change all the subsequent verifications for a specific method should you had to change a verification in the beginning of your test method. This new mechanism, not only makes OCMockito more similar to other mocking frameworks in the market, but it also makes your verifications completely independent from each other.


Reply to this email directly or view it on GitHub.

v3.0.0 "Previously verified invocations are no longer considered for verification." The bump of the major version number from v2 to v3 indicates the potential to break backwards compatibility.

I'll call out your example more clearly…

Updated change log e48349b with clearer explanation. Thanks @Autoc0diq for raising this issue — you weren't the only one caught off guard.

@jonreid Would be nice if you could also update the changelog on the Github releases page! 😊

Oh, you're right. Thanks, @lumaxis!