Tag: unit testing

How to test a class that makes HTTP request and parse the response data in Obj-C?

I Have a Class that needs to make an HTTP request to a server in order to get some information. For example: – (NSUInteger)newsCount { NSHTTPURLResponse *response; NSError *error; NSURLRequest *request = ISKBuildRequestWithURL(ISKDesktopURL, ISKGet, cookie, nil, nil); NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; if (!data) { NSLog(@”The user’s(%@) news count could not be obtained:%@”, […]

Objective-C initialize (static method) called more that once?

I have code similar to this in Objective-C: SubclassOfNSObject *GlobalVariableThatShouldNeverChange; @implementation MyClass +(void) initialize { [super initialize]; GlobalVariableThatShouldNeverChange = [[SubclassOfNSObject alloc] init]; // Change more stuff with GlobalVariableThatShouldNeverChange } @end I have this referenced throughout code, and the pointer to this should never change because I am using it everywhere through my code. The problem […]

Unit testing thread-based code? Forcing a race condition

In using my application, I’ve stumbled upon a race condition in some code that uses a NSOperationQueue to run tasks asynchronously following user-triggered events. I know how to fix the race condition, since it’s a stupid design error that I won’t delve into, but I’d like to prove the bug with a test case (so […]

Why does a false assertion in async test in GHUnit crash the app instead of just failing the test?

This question has very few views and no answers yet. If you have a suggestion what to change about this question to get more eyeballs, I’d be happy to hear them. Cheers! I’m using GHAsyncTestCase to test a custom NSOperation of mine. I’m setting the test case as a delegate on the operation object and […]

Unit Testing and Code Coverage Frameworks for Objective-C?

I’m planning to write couple applications for iPhone and wonder if there are any Unit Testing and Code Coverage Frameworks for Objective-C?

How do i mock a method that accepts a handle as an argument in OCMock?

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, regardless […]

“Test After Build” option in XCode 4 not working

So, I am having a bear of a time figuring this one out. I have looked around, and cannot seem to find any information on this. What I want to do is have my unit tests ALWAYS run EVERY time I build my code in XCode. I have read a number of posts, including this […]

How to mock class method (+)?

This question already has an answer here: Objective C & OC Mock – Mocking a class method? 4 answers

isKindOfClass: returns false negative in unit test bundle

So I have an instance of MyViewController in the detail view of a UISplitViewController. I am running a unit test to see whether the detail view contains the correct type of view. I test the type of controller in the unit test with the following: [controller isKindOfClass:[MyViewController class]]; However, the isKindOfClass method always returns NO […]

NSBundle pathForResource returns nil

I’ve been trying to load a simple text file in a unit test for an iOS app. NSString* resourcePath = [[NSBundle mainBundle] pathForResource: @”stopPointsInCircleData” ofType:@”txt”]; NSString* stopPointData = [NSData dataWithContentsOfFile: resourcePath]; My problem is that pathForResource returns nil. The file stopPointsInCircleData.txt is located in the directory of the test code and the file is listed […]