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

restubbing method in OCMock does not seem to work?

I am confused why this doesn't work... [[[myObject stub] andReturnValue:@YES] isBadical]; NSLog(@"================> result: %i", [myObject isBadical]); [[[myObject stub] andReturnValue:@NO] isBadical]; NSLog(@"================> new result: %i",…
patrick
  • 9,290
  • 13
  • 61
  • 112
0
votes
0 answers

OCMock throwing EXEC_BAD_ACCESS when used for child view controllers

I have a XCTest case with the following code: #import #import @interface ChildViewControllerTests : XCTestCase @end @implementation ChildViewControllerTests -(void) testInitAddsPassedControllersAsChildViews { …
drekka
  • 20,957
  • 14
  • 79
  • 135
0
votes
1 answer

How to mock a property of an object conforming to a protocol and mocked by OCMock?

I'm following the examples in Test driven iOS Development and in one case there is a unit test that ensures that a delegate gets a 'dumbed down' version of an error method. So without going into too many details here are the relevant…
abbood
  • 23,101
  • 16
  • 132
  • 246
0
votes
1 answer

Mocking UITableViewCell and using isKindOfClass

I'm trying to mock and test UITableViewCells to make sure my configureCell:forIndexPath works correctly, except I can't get it to work using isKindOfClass but only conformsToProtocol. This would require all of my uitableviewcells to have it's own…
0
votes
2 answers

OCMock stub class methods of the class that is being tested

+(NSString *) classMethod:(id)someDataObject { NSString *returnStr; //do something with someDataObject and set returnStr //... returnStr = [NSString stringWithFormat:@"%@%@", returnStr,[self getCurrentTimestamp]]; return…
sash
  • 8,423
  • 5
  • 63
  • 74
0
votes
1 answer

Issue stubbing a method

I'm working with CoreBluetooth, so in my unit tests I'm mocking all the CB objects so they return what I want. In one of my tests, I mock a CBPeripheral, and stub the delegate method like so: [[[mockPeripheral stub] andReturn:device] delegate]; The…
Mark
  • 7,167
  • 4
  • 44
  • 68
0
votes
1 answer

Unit Testing in xcode(Using GHUnit and OCMock)

In xcode,I am trying to do unit Testing using GHUnit and OCMock as described here : Unit Testing Xcode And Set Up methods as descibed here : GHUnitTestCase But got the error in this method (void)setUpClass { } when I initialize my ViewController…
Ponting
  • 2,248
  • 8
  • 33
  • 61
0
votes
0 answers

iOS OCMock: Text Files

I have a .txt file that I'd like to unit test. Is there a way with OCMock to make a "fake" test files for testing purposes? The behavior of my application depends on whats in the text file and ideally I'd like to write a unit test with different…
user1802143
  • 14,662
  • 17
  • 46
  • 55
0
votes
1 answer

Adding a root view controller OCMockObject[UIViewController] as a child view controller error

I've been working on my unit tests for iOS programming, and I've run into a little problem when trying to validate my main class by mocking it's child classes using OCMock and then seeing if the main class adds the child controllers…
iRunner
  • 58
  • 8
0
votes
2 answers

Unit test for complex methods using OCMock

How to write a unit test using OCMock for a complex methods which is having so many "if conditions" and the contions are checking for array count. Here is my sample method: - (BOOL)someMethod { BOOL bUploadingLocation = false; CLLocation…
chandvoid
  • 133
  • 1
  • 12
0
votes
1 answer

What's the equivalent of EasyMock.aryEq function in OCMOCK

I have a problem when i try to implement some tests in IOS using OCMOCK; Indeed, i need the equivalent of easy mock ary eq to expect byte array argument is equal to the given array. here's an example: invoked: …
0
votes
1 answer

How to write a unit test that checks that pressing the button will cause to calling the proper IBAction?

I need to write a unit test that checks that pressing the button will cause the proper IBAction to be called. Here is my test method: - (void)testWhether_loginBtnTapped_IsCalledAfterUserTapLoginButton { UIStoryboard *storyboard = [UIStoryboard…
0
votes
2 answers

OCMock. Why does the second of these test pass?

I am getting up to speed of mock-ing with iOS using OCMock. I wrote a simple mock-ing unit test that passes when - based on the expectation I set - it should fail. Here is the code: // Scientific Calculator class @implementation…
dugla
  • 12,774
  • 26
  • 88
  • 136
0
votes
2 answers

Testing class method using OCMock release 2.1.1

I am trying to check if a class method is getting invoked using OCMock. I have gathered from OCMock website and other answers on SO that the new OCMock release (2.1) adds support for stubbing class methods. I am trying to do the…
Warrior
  • 39,156
  • 44
  • 139
  • 214
0
votes
1 answer

Very simple basic OCMock stub not working

I'm experimenting with using OCMock but so far my simple experiment is failing. Given this experimental class that I want to mock: @interface HTTPConnection : NSObject @property (strong, nonatomic) NSURLConnection …
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378