Questions tagged [ocmockito]

OCMockito is an Objective-C implementation of Mockito, supporting creation, verification and stubbing of mock objects.

Key differences from other mocking frameworks:

  • Mock objects are always "nice," recording their calls instead of throwing exceptions about unspecified invocations. This makes tests less fragile.
  • No expect-run-verify, making tests more readable. Mock objects record their calls, then you verify the methods you want.
  • Verification failures are reported as unit test failures, identifying specific lines instead of throwing exceptions. This makes it easier to identify failures. (It also keeps the pre-iOS 5 Simulator from crashing.)
70 questions
1
vote
1 answer

OCHamcrest matcher parameter is incompatible with Mockito mock at Verify

with the following unit test I'm using Mockito to mock NSUserDefaults but when I try to verify using OCHamcrest matcher to test that the param is an instance of an NSDictionary I get the warning: Sending 'id{HCMatcher}' to parameter of incompatible…
stan4th
  • 710
  • 1
  • 6
  • 19
1
vote
1 answer

ios TDD with Kiwi, OCHamcrest and OCMockiti, can they be mixed?

Has anyone successfully got OCHamcrest working with Kiwi? I have started a Kiwi project then I added OCHamcrest framework and got a successful build. However when I tried to assert a condition in my Kiwi test file using hamcrest: it(@"has 3…
Armin
  • 1,367
  • 1
  • 12
  • 17
0
votes
1 answer

stubbing method with OCMockito

Hi I had a problem when testing a method that send a object message when I Run, the test failed and show me this error: failed: caught "NSInvalidArgumentException", "*** -[NSProxy doesNotRecognizeSelector:sendMessage:] called!" this is my test…
Walid Sassi
  • 185
  • 2
  • 16
0
votes
1 answer

Stubbing Protocol return as nil OCMockito

I've tried to stub the protocol method but it return as nil. Please check the following code. @protocol Client - (Account* _Nullable) login:(nullable NSString*)username password:(nonnull NSData*)login; And I…
Aye
  • 265
  • 1
  • 3
  • 13
0
votes
1 answer

Does OCMockito reset invocation count after a verify() call?

Here is the pseudocode of my unit test: int invocationCount given(mock).willDo { invocationCount++ return value } doSomeProcessing() verify(mock) doSomeMoreProcessing() verifyCount(mock, 2) At this point, invocationCount == 2, as expected.…
cohenadair
  • 2,072
  • 1
  • 22
  • 38
0
votes
1 answer

How to write unit test for method which instantiates collaborators inside itself?

Method code like so: - (void)downloadSomething:(NSString *)url { Downloader *downloader = [[Downloader alloc] initWithUrl:url]; NSData *data = [downloader download]; FileCache *cache = [[FileCache alloc] initWithFile:@"download.cache"]; …
ccnyou
  • 337
  • 2
  • 11
0
votes
1 answer

OCMockito how to capture block and match any other primitive arguments?

method signature: - (void)updateFeaturesButtons:(NSInteger)gameId category:(FeatruesCategory)category parentId:(NSInteger)parentId success:(void (^)(NSDictionary* featuresJson))success …
ccnyou
  • 337
  • 2
  • 11
0
votes
1 answer

OCMockito get count of invocations on mock

How can one get the count of invocations on a mocked object? At a particular point in a test I'd like to get the current count of invocations for a certain method, then continue the test and finally validate that the method was invoked one more…
0
votes
1 answer

OCMockito / OCHamcrest verify array contains object property

I'm creating an application which adds some local notifications. This is my test - (void)testFirstLogin { //some initials array NSArray *withoutFriends = @[@"a", @"b", @"c", @"e", @"f"]; NSArray *withFriends = @[@"v", @"w", @"x", @"y", @"z"]; //my…
milczi
  • 7,064
  • 2
  • 27
  • 22
0
votes
0 answers

OCMockito: get SIGABRT in async when using MKTArgumentCaptor in a not called verification

- (void)test_pushRightController UINavigationController naviMock = mock(UINavigationController); XCTestExpectation *e = [self expectationWithDescription:@"xnothing"]; self.model.navi = mockNavi; [self.model.buttonTapCommand…
CarmeloS
  • 7,868
  • 8
  • 56
  • 103
0
votes
1 answer

OCMockito: verify that a method of a mock is called sometime in the future

First I mock an object. Then I do something that should make the object's certain method be called. The call is asynchronous. So what I'd like to verify is: in at most 5 seconds, this method of the mock object should be called. Any idea?
CarmeloS
  • 7,868
  • 8
  • 56
  • 103
0
votes
1 answer

OCMockito: how do you express "any CGRect" when verifying a function call parameter?

Let's say that I have a method like this [SomeObject someMethod:(id)object someRect:(CGRect)rect]; When doing unit test, I want to very that this function is called with a specific object and any rect, but this code doesn't…
CarmeloS
  • 7,868
  • 8
  • 56
  • 103
0
votes
1 answer

Is there a way in OCMockito to make stubs fail when an unknown method is called?

When creating a stub in OCMockito, I use calls like this to stub out method calls and their return values: [given([stubObject myMethod]) willReturn:someValue]; The problem I have is that if I don't define a method an that method gets called during…
Didier Malenfant
  • 729
  • 1
  • 10
  • 25
0
votes
1 answer

isKindOfClass for mocked objects with OCMockito returns nil

I am testing a method, this method call other one that iterates over a NSArray of different objects, these objects conform a protocol . This method checks if every object isKindOfClass: oneClass or otherClass and return one to…
croigsalvador
  • 1,993
  • 2
  • 24
  • 47
0
votes
1 answer

How to properly cast this class for OCMockito?

I'm using OCMockito to mock some objects in my tests. When I use verify I receive an error from Xcode: Multiple methods named '.....' found with mismatched result, parameter type or attributes In the readme of the project i found this note: (If…
IgnazioC
  • 4,554
  • 4
  • 33
  • 46