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
8
votes
4 answers

What's the best way to assert on a UIImage in a unit test?

Say I'm writing a unit test for a tableView:cellForRowAtIndexPath: delegate method on a view controller. This method could return a couple of different configurations of cells depending on the index path I pass in. I can easily assert on the…
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97
7
votes
1 answer

OcMock vs OcMockito - what are pros and cons

For iOS tdd testing/mocking which framework would you recommend? I heard that OcMock has been around longer and is more lightweight. Could anyone provide a few examples of the pros and cons or demo some strengths of each. I'm just looking for a…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
6
votes
2 answers

Some verification involving block methods and OCMockito

I'm using OCMockito and I want to test a method in my ViewController that uses a NetworkFetcher object and a block: - (void)reloadTableViewContents { [self.networkFetcher fetchInfo:^(NSArray *result, BOOL success) { if (success) { …
Juan Herrero Diaz
  • 833
  • 1
  • 7
  • 17
6
votes
1 answer

How does one unit test code that interacts with the Core Bluetooth APIs?

I would like to unit test a class that acts as a CBPeripheralManagerDelegate to the CBPeripheralManager class. Typically, in order to stub out an external class dependency, I would use either a form of dependency injection by passing in via the…
Michael McGuire
  • 3,770
  • 2
  • 29
  • 28
5
votes
1 answer

How to stub CocoaLumberjack or NSLog with OCMockito

I can stub/verify a class method, but I'm having difficulty with defined macros. I'm trying to test that one of my methods calls DDLogInfo. It's defined like so in the CocoaLumberjack source #define DDLogInfo(frmt, ...) …
kreek
  • 8,774
  • 8
  • 44
  • 69
5
votes
2 answers

Test code with dispatch_async calls

Following TDD I'm developing an iPad app that downloads some info from the internet and displays it on a list, allowing the user to filter that list using a search bar. I want to test that, as the user types in the search bar, the internal variable…
4
votes
1 answer

OCMockito capturing primitive types?

How do I use OCMockito to capture argument with primitive values? MKTArgumentCaptor seems to be able to capture only object types? Xcode says "Incompatible pointer to integer conversion".
huggie
  • 17,587
  • 27
  • 82
  • 139
4
votes
1 answer

OCMockito verify with any arguments

I'm trying to verify that a function on a mock object is NOT called at all with ANY parameters. The function on the object I'm mocking is... - (void)registerUserWithUsername:(NSString*)username password:(NSString*)password; I'd like to verify that…
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
4
votes
1 answer

Verify method call with a handle argument on an OCMockito mock

I have an OCMockito mock of a class QuestionBuilder with the method questionsFromJSON:error:. This method accepts a handle (NSError **)error as an argument. How do I verify the method was called? I’ve tried: [verify(builder)…
Endersstocker
  • 1,061
  • 9
  • 26
3
votes
1 answer

Verify method call within init* with OCMockito

I would like to test if my init* method calls some other method within its body with OCMockito. Is this possible and if, how can I do it? Let's say, that I want to check if [self myMethod] has been called. I've been trying to do it in a such naive…
tgrf
  • 33
  • 3
3
votes
0 answers

OCMockito IOS - Crash on Xcode 5.1

I´m getting a crash on OCMockito, when calling methods from a mock object. Only using OCMockito-1.2.0 Basically, what i´m doing is: Include the OCHamcrestIOS.framework and OCMockitoIOS.framework . In the frameworks folder. Also check the copy if…
supersabbath
  • 364
  • 3
  • 8
3
votes
1 answer

Using OCMockito how can one verify any selector was passed to a method

I have a view controller that adds itself as an observer of UIApplicationDidBecomeActiveNotification during viewDidLoad. I'd like to verify that this happens but I don't want the test to care what specific selector the view controller registers for…
Cruinh
  • 3,611
  • 4
  • 38
  • 45
3
votes
2 answers

Exception while stubbing method with pass-by-reference in OCMockito

I'm trying to use OCMockito to stub an NSJSONSerialization method. I thought I had a solution, but it turns out it causes this exception: *** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1] Here's what I was doing: Class mockClass =…
Cruinh
  • 3,611
  • 4
  • 38
  • 45
3
votes
1 answer

OCMockito anything() for primitive types

For method signature - (void)insertValue:(NSUInteger)value; I'm trying to see if insertValue for any value never gets called. [verifyCount(test, never()) insertValue:0]; Since compiler complains anything() primitive types, how do I test this?
huggie
  • 17,587
  • 27
  • 82
  • 139
3
votes
1 answer

OCMockito mocking calls with block

I want to mock an object with the following message declaration: - (void)createWithCompletion:(void (^)(FuseResult *result, NSError *err)) completion; Is it possible to mock the block call this message has to handle? I read the ArgumentCaptorTest…
huggie
  • 17,587
  • 27
  • 82
  • 139
1
2 3 4 5