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
2
votes
1 answer

OCMock - accessing weak properties of a partially mocked object causes sporadic crash

I'm using OCMock to test UIViewControllers that are instantiated from a storyboard. Following best practice, all IBOutlets of subviews of the view controller's view are weak properties. When I'm writing tests for these view controllers in which…
Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
2
votes
1 answer

Cannot Stub method "title" because no such method exist in the mocked class OCMock

I'm writing this unit test: - (void)testCellValues { id bookMock = [OCMockObject mockForClass:[LBBook class]]; [[[bookMock stub] andReturn:@"Book Title"] title]; } Of course there is some code after that. But at this point I'm having…
Gabriel Goncalves
  • 5,132
  • 3
  • 25
  • 34
2
votes
2 answers

How can I access local variables within a method for an XCTestCase using OCMock?

I have a method that I want to test that does this: - (void)openEmailFeedback { MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = self; [controller…
Byron Duenas
  • 161
  • 1
  • 8
2
votes
2 answers

OCMockObject mocking an instance method

I am new to OCMockObjects and trying to mock an instance method of ACAccount class: -(NSArray *)accountsWithAccountType:(ACAccountType *)accountType; I wrote this code in the test class to intialize mockObject: ACAccountStore *accountStore =…
Amit
  • 1,043
  • 1
  • 10
  • 32
2
votes
2 answers

How to mock a C-function using OCMock

How do I mock a custom c-lib function using ocmock? Couldn't find anything on google, and any method stubbing functions from OCMock doesn't work
Kevin Liang
  • 206
  • 2
  • 11
2
votes
0 answers

Why doesn't OCMock see class methods in extensions?

I am using UIAlertView+Blocks from https://github.com/ryanmaxwell/UIAlertView-Blocks, which adds a tapBlock property to UIAlertView, with OCMock. id mockView = [OCMockObject mockForClass:[UIAlertView class]]; [[[mockView stub]…
dB.
  • 4,700
  • 2
  • 46
  • 51
2
votes
1 answer

OCMock a Class method to call back the passed block with custom Data

I do have a class that handles all my network communication like this: typedef void (^ networkEndblock) (NSArray *, NSError *); @interface NetworkAPI : NetworkBase + (void) doSomeNetworkAcion:(networkEndblock) endBlock; @end I use the above code…
UserNil
  • 129
  • 9
2
votes
1 answer

OCMock test not getting compiled with XCTest

Has anyone tried using OCMock test framework with XCTest framework? We were using OCMock test framework with SenTest framework and ever since we migrate from SenTest to XCTest, OCMock tests stops compiling. I know, XCTest does not have in-built…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
2
votes
2 answers

How to mock AFHTTPClient class and test method getPath:parameters:success:failure:?

I'm new with AFNetworking framework. I've got implemented simple GET request to the server. @implementation MyClass … - (void)signInWithUsername:(NSString *)username andPassword:(NSString *)password withBlock:(SignInBlock)block { [client…
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
2
votes
1 answer

Issue with OCMock 2.2.1, Xcode 5.0.2, XCTest and mocking of class methods (declared in a category)

Intro: I have the tool (Xcode 5.0.2), library (OCMock 2.2.1) and test (XCTest) setup mentioned in the title of this question. Category: I have a category on NSObject with a class method like this: + (BOOL) hasDeclaredPropertyWithName: (NSString*)…
Nenad M
  • 3,055
  • 20
  • 26
2
votes
1 answer

Mocking class selectors with OCMock

I'm trying to test a class that implements two class methods from NSURLConnection, but keep getting the error: error: testSyncConnection (MyURLConnectionTest) failed: *** -[NSProxy…
Mostafa Berg
  • 3,211
  • 22
  • 36
2
votes
2 answers

Expect method calls from non-instantiated variable with OCMock

I'm not sure if that was the best title, but basically I know that a variable will become instantiated upon running a function. I want to do a partial mock of this variable and expect certain method calls before the variable is instantiated. Here's…
Ryan Schulze
  • 87
  • 2
  • 10
2
votes
1 answer

Calling + [NSBundle bundleForClass:] on a partially mocked object is returning a different result than the unmocked object?

I am working on unit tests using XCTest and OCMock 2.2.1. I have a class that obtains the bundle identifier using: NSString *bundleIdentifier = [[NSBundle bundleForClass:[self class]] bundleIdentifier]; This works as expected while running the…
2
votes
1 answer

Using OCMock on NSOperation gives bad access

I was writing a unit test and it was giving me trouble. Turns out I can reproduce the trouble using just OCMock and normal obj-c. So I am sharing my simple test that reproduces my problem here in the hope that someone can help me understand why it…
CodeReaper
  • 5,988
  • 3
  • 35
  • 56
2
votes
1 answer

Why can't I stub this method of GKTurnBasedParticipant using OCMock?

Here is an OCUnit test that simply stubs the method playerID of GKTurnBasedParticipant: #import #import "OnlineMatchTest.h" #import "OCMock.h" @implementation OnlineMatchTest - (void)setUp { GKTurnBasedParticipant…
Tom
  • 3,831
  • 1
  • 22
  • 24