iphone OCMockObject and unit-testing a class that inherits from NSURLConnection
Posted
by Justin Galzic
on Stack Overflow
See other posts from Stack Overflow
or by Justin Galzic
Published on 2009-12-31T01:51:03Z
Indexed on
2010/04/06
16:03 UTC
Read the original article
Hit count: 459
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 do this?
- (void)testInit
{
id urlRequest = [OCMockObject mockForClass:[NSURLRequest class]];
MyURLConnectionWrapper *conn = [[MyURLConnectionWrapper alloc]
initWithRequest:urlRequest delegate:self
someData:extraneousData];
}
My class is implemented like this:
@interface MyURLConnectionWrapper : NSURLConnection {
}
- (id)initWithRequest:(NSURLRequest *)request
delegate:(id)delegate someData:(NSString *)fooData
@end
@implementation MyURLConnectionWrapper
- (id)initWithRequest:(NSURLRequest *)request
delegate:(id)delegate someData:(NSString *)fooData
{
if (self = [super initWithRequest:request delegate:delegate])
{
// do some additional work here
}
return self;
}
Here's the error I get:
OCMockObject[NSURLRequest]: unexpected method invoked: _CFURLRequest
© Stack Overflow or respective owner