ocmock

Unit Test CLLocationManager implementation

瘦欲@ 提交于 2019-12-25 04:53:17
问题 I have a class named " GeolocationManager " that handles a CLLocationManager object and delegate responses. - (void)getGeolocationForClient:(id<GeolocationManagerDelegate>)client { _delegate = client; _locationManager = [self createLocationManager]; _locationManager.delegate = self; _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; [_locationManager startUpdatingLocation]; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { // do some

OCMock setup for OSX with CocoaPods

て烟熏妆下的殇ゞ 提交于 2019-12-25 03:57:19
问题 Trying to setup OCMock for a OSX project. Problem is I am not getting any framework to add to my test target, only the static library. I doubt it should be like that. In my Podfile I have the following: pod 'OCMock', '~> 2.2' 回答1: This was solved by selecting the project in XCode and select "Yes" under "Always Search User Paths". 来源: https://stackoverflow.com/questions/23284442/ocmock-setup-for-osx-with-cocoapods

OCMock - Unexpected Method Invoked although expected

邮差的信 提交于 2019-12-24 10:52:55
问题 Here is the tested code: if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailComposeController = [[MFMailComposeViewController alloc] init]; [mailComposeController setSubject:nil]; [mailComposeController setToRecipients:@[Text_Email_Me_Email]]; [mailComposeController setMailComposeDelegate:self]; [self.frontViewController presentViewController:mailComposeController animated:YES completion:nil]; } Here is the testing code: id mailComposerMock = [OCMockObject

OCMock automatically use mocked instance in code under test?

一世执手 提交于 2019-12-23 13:07:04
问题 I am new in OCMock. I use dispatch_once() created a singleton class MyManager : @implementation MyManager + (id)sharedInstance { static MyManager *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedMyManager = [[self alloc] init]; }); return sharedMyManager; } I have a method in School class which uses the above singleton: @implementation School ... - (void) createLecture { MyManager *mgr = [MyManager sharedInstance]; [mgr checkLectures]; ... } @end

Why does OCMock partialMock break KVO?

不羁的心 提交于 2019-12-23 12:57:54
问题 If I have an object that uses KVO to observe a property on some object and then create a partial mock for that observer I no longer receive any notifications. Why is this? Here's a minimal example: @interface TestPartialMockAndKVO : SenTestCase @end @implementation TestPartialMockAndKVO - (void)test { // Should print "Changed!" when foo property is changed MyObserver* myObserver = [[[MyObserver alloc] init] autorelease]; // But with this line, there is no print out [OCMockObject

Why doesn't OCMock see class methods in extensions?

痞子三分冷 提交于 2019-12-23 00:28:31
问题 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] andReturn:mockView] alloc]; // this works [[mockView expect] setTapBlock:OCMOCK_ANY]; // this doesn't, it doesn't know what tapBlock is [[mockResetPasswordView expect] tapBlock:OCMOCK_ANY]; The tapBlock is declared as @property (copy, nonatomic)

Xcode 6, Swift and mock verification without exceptions

谁说胖子不能爱 提交于 2019-12-22 10:31:19
问题 Anyone know how to verify an OCMock expect in Swift? Swift Doesn't use Exceptions so XCTest no longer includes XCTAssertNoThrow . Is There any other way to verify a method was called with OCMock? I noticed in OCMock the verify function checks the expectations array so I assume we could do XCTAssertTrue(mock.expectations == 0) if we had access. Trying to figure some of these more complicated things out since there is little to no docs around XCTests in Swift 回答1: Ok so Not a real answer but a

OCMock 3.0.2 linker error with .mm test file

断了今生、忘了曾经 提交于 2019-12-22 08:23:51
问题 I am using OCMock 3.0.2, which I've installed through cocoapods for my test target: platform :ios, '7.0' xcodeproj 'myProject.xcodeproj' target :myTestTarget do pod 'OCMock', '~> 3.0.2' end link_with "myTestTarget" In my test file (myTest.mm), I've included OCMock and want to try out the new verify-in-place strategy, like so: - (void) test_myTest { MyObject *obj = [MyObject new]; id robotMock = OCMPartialMock(obj); [obj testMethod]; // some asserts OCMVerify([obj _internalMethodToBeCalled]);

How to I capture an argument sent to a mock?

江枫思渺然 提交于 2019-12-22 05:48:08
问题 Does anyone know how to capture an argument sent to an OCMock object? id mock = [OCMockObject mockForClass:someClass] NSObject* captureThisArgument; [[mock expect] foo:<captureThisArgument>] [mock foo:someThing] GHAssertEquals[captured, someThing, nil]; How do I go about validating the argument to foo? I'm happy to do it within a block in the mock definition too, but if I could get the object out so that I can assert on feature of it later that would be brilliant. Is this possible with OCMock

OCMock - verifying order of method calls. Is there any other way?

做~自己de王妃 提交于 2019-12-22 05:28:19
问题 When I want to verify that in one method a mock object is receiving some messages in a particular order I do something like this: // sut is an instance of the class I am testing and myMock is a mock object injected in sut. // I want to test that myMock sends messageA and then messageB, in that particular order. [[[myMock expect] andDo:^(NSInvocation *invocation) { [[myMock expect] messageB]; }] messageA]; [sut methodToTest]; [myMock verify]; Is there any cleaner/better way of doing this?