ocmock

How do you mock out private properties with OCMock for iOS?

不想你离开。 提交于 2019-11-29 02:52:13
问题 I have a private property that is declared in the .m file of my class to be tested, let's call it ClassUnderTest. ClassUnderTest instantiates an instance of ClassToBeMocked. How do I use OCMock to mock out an instance of the ClassToBeMocked and assign it to the ClassUnderTest? 回答1: Re-declare the property in your test class. You can do the same for private methods. In ClassUnderTestTest.m: @interface ClassUnderTest () @property(retain)ClassToBeMocked *instanceToBeMocked; -(void

How to stub a class method in OCMock?

我的梦境 提交于 2019-11-29 01:32:05
问题 I often find in my iPhone Objective-C unit tests that I want stub out a class method, e.g. NSUrlConnection's +sendSynchronousRequest:returningResponse:error: method. Simplified example: - (void)testClassMock { id mock = [OCMockObject mockForClass:[NSURLConnection class]]; [[[mock stub] andReturn:nil] sendSynchronousRequest:nil returningResponse:nil error:nil]; } When running this, I get: Test Case '-[WorklistTest testClassMock]' started. Unknown.m:0: error: -[WorklistTest testClassMock] : ***

OCMock with Core Data dynamic properties problem

倾然丶 夕夏残阳落幕 提交于 2019-11-29 00:26:49
问题 I'm using OCMock to mock some Core Data objects. Previously, I had the properties implemented with Objective-C 1.0 style explicit accessors: // -- Old Core Data object header @interface MyItem : NSManagedObject {} - (NSString *) PDFName; - (void) setPDFName:(NSString *)pdfName; @end // -- implementation provides generated implementations for both getter and setter Now I've moved the code to Objective-C 2.0 and want to take advantage of the new @property syntax, and the dynamically-generated

Testing use of NSURLConnection with HTTP response error statuses

怎甘沉沦 提交于 2019-11-28 18:20:17
I'm writing an iPhone application that needs to get some data from a web server. I'm using NSURLConnection to do the HTTP request, which works well, but I'm having trouble unit testing my code in the case where the response has an HTTP error code (like 404 or 500). I'm using GTM for unit testing and OCMock for mocking. When the server returns an error, the connection does not call connection:didFailWithError: on the delegate, but calls connection:didReceiveResponse: , connection:didReceiveData: , and connectionDidFinishLoading: instead. I'm currently checking the status code on the response in

Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted

天大地大妈咪最大 提交于 2019-11-28 17:17:54
问题 I have started working with OCMock to write test cases for the existing project that i have integrated in my project workspace. After following all the steps mentioned in this link When i first executed my test case its giving me this error. I searched it and tried following some of the solutions like "creating new target"," restarting Xcode" but it didn't help me out. Any Idea? 回答1: I have my notes and demo applications for both Cocoapods and Carthage here https://github.com/onmyway133

Testing use of NSURLConnection with HTTP response error statuses

喜你入骨 提交于 2019-11-27 11:14:48
问题 I'm writing an iPhone application that needs to get some data from a web server. I'm using NSURLConnection to do the HTTP request, which works well, but I'm having trouble unit testing my code in the case where the response has an HTTP error code (like 404 or 500). I'm using GTM for unit testing and OCMock for mocking. When the server returns an error, the connection does not call connection:didFailWithError: on the delegate, but calls connection:didReceiveResponse: , connection