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 a Hamcrest matcher. No die. The function/method I'm testing looks something like this:
-...
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 ...
I'm wondering how to go about testing this. I have a method that takes a parameter, and based on some properties of that parameter it creates another object and operates on it. The code looks something like this:
- (void) navigate:(NavContext *)context {
Destination * dest = [[Destination alloc] initWithContext:context];
if (conte...
I'm trying to mock a UITabBarController in my app's tests. I have a category method on that class defined elsewhere in another file that gets imported along with ocmock in my test class. what i'm trying to so is this:
- (void) setUp
{
id mockTabController = [OCMockObject mockForClass:[UITabBarController class]];
[[[mockTabCont...
I'm trying to mock a method that has the equivalent of the following signature:
- (NSDictionary *) uploadValues:(BOOL)doSomething error:(NSError **)error
I want it to return a small dictionary so that my test can make sure the code uses the dictionary properly. however, no matter what i do OCMock always returns nil from the method, r...
I know this SO question, but it deals with the subject in more general terms.
Should I prefer using partial Mocks over Dependency Injection? My question is based on the following quote from OCMock:
id aMock = [OCMockObject partialMockForObject:anObject]
Creates a mock object that can be used
in the same way as anObject. When a
...
Hey all,
I'm trying to write a test for a method where the output depends on an NSDate's timeIntervalSinceNow return value. I'd like to specify the return value in my tests so I can test certain scenarios.
I'm having a really hard time getting this OCMock object returning what I'd like. Here's my code:
id mock = [OCMockObject mockForC...
I'm using OCMock trying to test the behavior of NSURLConnection. Here's the incomplete test:
#include "GTMSenTestCase.h"
#import <OCMock/OCMock.h>
@interface HttpTest : GTMTestCase
- (void)testShouldConnect;
@end
@implementation HttpTest
- (void)testShouldConnect {
id mock = [OCMockObject mockForClass:[NSURLConnection class]];
...
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 ...
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 implementatio...
I want to unit test the custom init method of a class that inherits from NSURLConnection -- how would I do this if the init of my testable class invokes NSURLConnection's initWithRequest?
I'm using OCMock and normally, I can mock objects that are contained within my test class. For this inheritance scenario, what's the best approach to ...
Is NSInvocation class not meant to be called via unit tests (for iPhone)?
My intent is to call a class's method generically and since the method has more than 2 parameters, I can't use [myTestClass performSelector:withObject:withObject]
Instead, I'm trying to use NSInvocation but as soon as I try to instantiate from NSInvocation class,...
I have a class that relies on NSUserDefaults that I'm trying to unit-test and I'm providing the NSUserDefaults as a mock into my test class. When running the test, I get the error:
OCMockObject[NSUserDefaults]:
unexpected method invoked:
dictionaryForKey:@"response"
I'm trying to mock this instance method of the NSUserDefaults ...
I am just grasping the concepts of TDD and mocking, and am running into an issue in terms of how to properly. I have a sheet that drops down and lets a user create a new core data object and save it to the data store. I am not sure if I am taking the best approach to testing it.
- (IBAction)add:(id)sender
{
NSString *itemName = [...
Hi,
I am a Xcode beginner, and am facing some problems in compiling an OCMock test. I have added the OCMock.framework in "Groups & Files", and then added a very basic OCMock test from the Unit testing target, basically for Canary testing.
When I compile the OCMockTests.m file, the system returns around 38 errors pointing out all the i...
My problem is I am getting an error:
OCMckObject[NSNumberFormatter]:
expected method was not
invoked:setAllowsFloats:YES
I have written following Code:
(void) testReturnStringFromNumber
{
id mockFormatter = [OCMockObject mockForClass:[NSNumberFormatter class]];
StringNumber *testObject = [[StringNumber alloc] init]; ...
At my day job I've been spoiled with Mockito's never() verification, which can confirm that a mock method is never called.
Is there some way to accomplish the same thing using Objective-C and OCMock? I've been using the code below, which works but it feels like a hack. I'm hoping there's a better way...
- (void)testSomeMethodIsNeverCal...
Hi,
I would like to test a method that uses reverse Geocoding. What i would like to do is :
set the geocoder as a property of my controller
create the geocoder in the init method
call the geocoder in the method i want to test
replace the geocoder with a mock in my test
The problem is that the MKReverseGeocoder coordinate property is...
Hi,
I need to test a method that calls a webservice. So i want to mock the webservice class using OCMock.
What i would like to do is tell my mock : when i try to call my webservice just forward the call to the didSucceed method and send it mock datas.
I can forward the call to the success method without problems using :
[[[myMock stub...
I've been having troubles to run OCMock with iOS 4.
I've read that a possible solution os to build the library, and install libOCMock.a, but honestly, i don't know how. Any help would be usefull
...