Questions tagged [ocmock]

OCMock is an Objective-C implementation of mock objects.

The OCMock framework provides the ability of using mock objects in Objective-C applications. Some of the functionality in the framework is:

  • Create fail-fast and nice mocks.
  • Ability to stub and return predetermined values.
  • Mock instance and class methods.
  • Mock protocols and notification observers.
  • Partial mocks to stand in for a real object.
  • Forward messages to other objects.

Relevant links

Web site

Source

484 questions
12
votes
2 answers

How to get the mocked value when calling isKindOfClass for an OCMock object?

Passing an OCMock object to a method where the function calls isKindOfClass. However for unit test, the value returned is not of the mocked class but OCMockObject
11
votes
6 answers

how to unit test a NSURLConnection Delegate?

How can I unit test my NSURLConnection delegate? I made a ConnectionDelegate class which conforms to different protocols to serve data from the web to different ViewControllers. Before I get too far I want to start writing my unit tests. But I don't…
Moxy
  • 4,162
  • 2
  • 30
  • 49
11
votes
1 answer

How to mock an object with OCMock which isn't passed as a parameter to method?

I have a method I would like to test with OCMock but not sure how to do that. I need to mock ExtClass which isn't defined as part of my code (external library): +(NSString *)foo:(NSString *)param { ExtClass *ext = [[ExtClass alloc]…
soguy
  • 265
  • 1
  • 3
  • 10
11
votes
3 answers

OCMock and block testing, executing

Here's the method under test: - (void)loginWithUser:(NSString *)userName andPass:(NSString *)pass { NSDictionary *userPassD = @{@"user":userName, @"pass":pass}; [_loginCntrl loginWithUserPass:userPassD…
Mark W
  • 3,879
  • 2
  • 37
  • 53
11
votes
3 answers

OCMock method name collision

i'm a new user of OCMock, so maybe i'm just missing something simple here. this code does not compile: id mockSession = [OCMockObject mockForClass:[AVCaptureSession class]]; [[mockSession expect] addOutput:[OCMArg anyPointer]]; the error…
Ben H
  • 3,855
  • 1
  • 26
  • 33
10
votes
3 answers

How can I get OCMock under ARC to stop nilling an NSProxy subclass set using a weak property?

Under ARC, I have an object, Child that has a weak property, parent. I'm trying to write some tests for Child, and I'm mocking its parent property using OCMock. Under ARC, setting an NSProxy subclass using a synthesized weak property setter doesn't…
10
votes
6 answers

Reset singleton instance to nil after each test case

I am using OCMock 3 to unit test my iOS project. I use dispatch_once() created a singleton class MyManager : @implementation MyManager + (id)sharedInstance { static MyManager *sharedMyManager = nil; static dispatch_once_t onceToken; …
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
10
votes
1 answer

iOS OCMock partial vs class mock

I am learning OCMock for iOS testing. What's the difference between "class mock" and "partial mock", and when should you use one vs the other? http://ocmock.org/features/
user1802143
  • 14,662
  • 17
  • 46
  • 55
9
votes
4 answers

Using a struct with OCMock or Hamcrest

I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with…
Cliff
  • 10,586
  • 7
  • 61
  • 102
9
votes
4 answers

Set readonly navigationController property on UIViewController for mocking

I have created a mock UINavigationController using OCMock. However, I cannot assign it to the navigationController property of a UIViewController since that property is readonly. id mockNavController = [OCMockObject…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
9
votes
3 answers

Verify a method was never called with OCMock 3

How do I verify a method is never called with OCMock 3? I was thinking something like this: XCTAssertThrows(OCMVerify([_restDataSource getSomeStuff:[OCMArg any]])); But it seems like OCMVerify doesn't throw for a fail.
Ev.
  • 7,109
  • 14
  • 53
  • 87
9
votes
1 answer

iOS Mocking Class That Has Side Effects on Class Load

We're trying to create a unit test (with OCMock although, open to other frameworks) that mocks a class that on class load has a side effect. We have a tracking class that wraps calls to other tracking libraries like Flurry. Many of these other…
Gary Rudolph
  • 1,062
  • 9
  • 21
9
votes
1 answer

OCMock forward to original class method

OCMock offers a nice syntax to mock class methods, but can class method calls be forwarded to the real class object? self.connectionMock = [OCMockObject mockForClass:NSURLConnection.class]; [[[[self.connectionMock stub] andDo:^(NSInvocation…
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
9
votes
1 answer

how to unit testing AFNetworking request

i am making a GET request to retrieve JSON data with AFNetworking as this code below : NSURL *url = [NSURL URLWithString:K_THINKERBELL_SERVER_URL]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; Account *ac =…
orthehelper
  • 4,009
  • 10
  • 40
  • 67
8
votes
1 answer

XCTest expect method call with swift

How to write a test that expects a method call using swift and XCTest? I could use OCMock, but they don't officially support swift, so not much of an option.
Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75
1
2
3
32 33