0
我正在嘗試使用OCMock,但到目前爲止,我的簡單實驗失敗了。鑑於這種實驗班,我想嘲笑:非常簡單的基本OCMock存根不工作
@interface HTTPConnection : NSObject <NSURLConnectionDelegate>
@property (strong, nonatomic) NSURLConnection *connection;
-(int) makeConnection:(NSString*) url; // implementation returns 5
@end
當我調用下面的測試情況下,結果變量包含5的15個這樣的現實對象的方法得到了調用,而不是模擬一個:
- (void)testExample
{
id connection = [OCMockObject mockForClass:[HTTPConnection class]];
[[[connection stub] andReturn: [NSNumber numberWithInt: 15]] makeConnection:[OCMArg any]];
HTTPConnection* realConnection = [[HTTPConnection alloc] init];
int result = [realConnection makeConnection:@"http://www.anything.com"];
}