Created
April 11, 2013 08:14
-
-
Save laiso/5361649 to your computer and use it in GitHub Desktop.
テストコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
id addressbook = [OCMockObject mockForClass:[RHAddressBook class]]; | |
id person = [OCMockObject mockForClass:[RHPerson class]]; | |
[[person expect] setFirstName:@"テスト"];// 実行順序 3 | |
[[person expect] setLastName:@"ユーザー"];// 実行順序 4 | |
[[person expect] save];// 実行順序 6 | |
RHMutableMultiValue* emails = [[RHMutableMultiValue alloc] initWithType:kABMultiStringPropertyType]; | |
[emails addValue:@"[email protected]" withLabel:(__bridge NSString*)kABWorkLabel]; | |
//厳密にチェックしない場合はOCMOCK_ANY渡してもよし | |
[[person expect] andCall:@selector(setEmails:) onObject:emails];// 実行順序 5 | |
[[[addressbook expect] andReturn:person] newPersonInDefaultSource];// 実行順序 2 | |
[self.device performSelector:@selector(setAddressbook:) withObject:addressbook];// テスト専用にインターフェース追加せず、プライベートメンバに差し込む作戦 | |
/// ここまでモックをジェネレートするブロック | |
// メインのテストコード | |
BOOL ret = [self.device addPersonToAddressbook:@{@"email": @"[email protected]", @"firstName": @"テスト", @"lastName": @"ユーザー"}];// 実行順序 1 | |
STAssertTrue(ret, nil); | |
/// ここからモックの検証をするブロック | |
[addressbook verify]; | |
[person verify]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment