???????? Data Source
??????????????????ɡ?????????????? view controller ?ò?????????????????????????????? ArrayDataSource??????????????????????????????????????????????????????????????????????? @interface ????????????????????????????
????#import "PhotoDataTestCase.h"  @interface ArrayDataSourceTest : PhotoDataTestCase @end  @implementation ArrayDataSourceTest - (void)testNothing; {     STAssertTrue(YES?? @""); } @end
???????????????£????????????????á?????????????????????-testNothing ???????????С??????STAssert ????????????顣????? ST ????? SenTestingKit????Щ??? Xcode ???????????????? Issues navigator ?С?
?????????????
????????????? testNothing ?滻???????????????????
- (void)testInitializing; {     STAssertNil([[ArrayDataSource alloc] init]?? @"Should not be allowed.");     TableViewCellConfigureBlock block = ^(UITableViewCell *a?? id b){};     id obj1 = [[ArrayDataSource alloc] initWithItems:@[]                                       cellIdentifier:@"foo"                                   configureCellBlock:block];     STAssertNotNil(obj1?? @""); }
??????? Mocking
?????????????????? ArrayDataSource ?????????
????- (UITableViewCell *)tableView:(UITableView *)tableView          cellForRowAtIndexPath:(NSIndexPath *)indexPath;
???????????????????????????
????- (void)testCellConfiguration;
???????????????? data source??
__block UITableViewCell *configuredCell = nil; __block id configuredObject = nil; TableViewCellConfigureBlock block = ^(UITableViewCell *a?? id b){     configuredCell = a;     configuredObject = b; }; ArrayDataSource *dataSource = [[ArrayDataSource alloc] initWithItems:@[@"a"?? @"b"]                                                       cellIdentifier:@"foo"                                                   configureCellBlock:block];
???????configureCellBlock ????洢???????????????????????????????????????????
???????????? table view ??????? mock ????
????id mockTableView = [OCMockObject mockForClass:[UITableView class]];
????Data source ??????????? table view ????? -dequeueReusableCellWithIdentifier:forIndexPath: ??????????????? mock object ??????????????????????????????? cell????????? mock??
????UITableViewCell *cell = [[UITableViewCell alloc] init]; NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [[[mockTableView expect] andReturn:cell]         dequeueReusableCellWithIdentifier:@"foo"                              forIndexPath:indexPath];
????????ο??????????????е????????????????????????? mock ??????????á?Mock ????????????? table view????????????????-expect ??????????????????? mock??????????????????????????????
????????-expect ????????? mock ????????????????????????? mock ????? -verify ???????????????б????ù??????????????????-stub ????????????? mock ???????????????????????ù???
?????????????????????????С?????????????????????????
????NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; id result = [dataSource tableView:mockTableView             cellForRowAtIndexPath:indexPath];
??????????????????????????
????STAssertEquals(result?? cell?? @"Should return the dummy cell."); STAssertEquals(configuredCell?? cell?? @"This should have been passed to the block."); STAssertEqualObjects(configuredObject?? @"a"?? @"This should have been passed to the block."); [mockTableView verify];
????STAssert ???????????????????????????????????????????????????????? -isEqual:??????????????????? result??cell ?? configuredCell ????????????????????????? -isEqual:??????????? mock ?? -verify ??????
?????????????????У??????????????? mock ???
????id mockTableView = [self autoVerifiedMockForClass:[UITableView class]];
???????????????????е?????????????????????????????? -verify ??????
???????? UITableViewController
???????棬??????? PhotosViewController??????? UITableViewController ????????????????????????? data source??View controller ??μ??????????????
??????????????? cell ????????????????棬????? PhotoViewController ??????? push ?? navigation controller ???檔?????????? mocking ???ò????????????????????????
?????????????????? UINavigationController ?? mock??
????id mockNavController = [OCMockObject mockForClass:[UINavigationController class]];
???????????????????? partial mocking????????? PhotosViewController ????? navigationController ???? mockNavController???????????????? navigation controller?????????????? PhotosViewController ??? stub ????????????????? mockNavController ???????
????PhotosViewController *photosViewController = [[PhotosViewController alloc] init]; id photosViewControllerMock = [OCMockObject partialMockForObject:photosViewController]; [[[photosViewControllerMock stub] andReturn:mockNavController] navigationController];
??????????κ????? photosViewController ???? -navigationController ???????????? mockNavController???????????????OCMock ?????????
?????????????????? navigation controller mock ????????????????????? photo ??? nil ?? detail view controller??
????UIViewController* viewController = [OCMArg checkWithBlock:^BOOL(id obj) {     PhotoViewController *vc = obj;     return ([vc isKindOfClass:[PhotoViewController class]] &&             (vc.photo != nil)); }]; [[mockNavController expect] pushViewController:viewController animated:YES];