????????????? View Controllers
???????????? ???????[ 2014/3/17 14:05:37 ] ???????????? ???????
???????????????? view ??????????????б??????
????UIView *view = photosViewController.view; STAssertNotNil(view?? @""); NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [photosViewController tableView:photosViewController.tableView didSelectRowAtIndexPath:indexPath];
????????????? mocks ????????????????ù???
????[mockNavController verify]; [photosViewControllerMock verify];
????????????????????????????????? navigation controller ????????????? view controller ???????
????????ε??????????????????????????????
????- (id)autoVerifiedMockForClass:(Class)aClass; - (id)autoVerifiedPartialMockForObject:(id)object;
???????????????????????? -verify??
????????????
????????????濴??????????partial mocking ????????????? -[PhotosViewController setupTableView] ????????????????????δ? app delegate ????? model ??????
????NSArray *photos = [AppDelegate sharedDelegate].store.sortedPhotos;
?????????????????????д?????????????????????????????? partial mocking???? app delegate ???????????????????????
????id storeMock; // assume we've set this up id appDelegate = [AppDelegate sharedDelegate] id appDelegateMock = [OCMockObject partialMockForObject:appDelegate]; [[[appDelegateMock stub] andReturn:storeMock] store];
????????????? [AppDelegate sharedDelegate].store ?????ù?????????? storeMock?????????????????????????????????????????????и?????????
?????μ????
????Partial mocks ????? mocking ??????????? mocks ????????????Ч????????????????? [aMock stopMocking] ?????????????????????????? partial mock ???????????????????Ч?????????????????? [aMock verify]?????? ARC ????? dealloc ??? mock???????????????????????? -verify??
???????? NIB ????
????PhotoCell ????????? NIB ?У????????д??????????????? outlets ????????????????????????? PhotoCell ??
????@interface PhotoCell : UITableViewCell + (UINib *)nib; @property (weak?? nonatomic) IBOutlet UILabel* photoTitleLabel; @property (weak?? nonatomic) IBOutlet UILabel* photoDateLabel; @end
??????????????????????????????
????@implementation PhotoCellTests - (void)testNibLoading; { UINib *nib = [PhotoCell nib]; STAssertNotNil(nib?? @""); NSArray *a = [nib instantiateWithOwner:nil options:@{}]; STAssertEquals([a count]?? (NSUInteger) 1?? @""); PhotoCell *cell = a[0]; STAssertTrue([cell isMemberOfClass:[PhotoCell class]]?? @""); // Check that outlets are set up correctly: STAssertNotNil(cell.photoTitleLabel?? @""); STAssertNotNil(cell.photoDateLabel?? @""); } @end
??????????????????????????
?????????????????????????????????????????? nib ?????????????????????????????? outlets ?仯????????????????????? .xib ?????????????????????????????????
???????? Class ?? Injection
??????????????? Xcode ???????????? bundle ???????ó????С??????????ι????????????????????????????????????????????? bundle?????????? bundle???е? Objective-C ?????????е???ó????С????????????????????????в??????
????????????????????????????????????????????????ó??????? bundle?С???????????????????У????????? PhotoCell ?????????? bundle ????ó??????????? bundle ?е??? [PhotoCell class] ???????????????????ó????е???????????????????????????
????STAssertTrue([cell isMemberOfClass:[PhotoCell class]]?? @"");
??????????????????????????????????????ó????е? .m ??????????? target ?С??????????????????????
????????????
????????????????????????????????????????????????????????????????????????????????Χ????Щ?????? RunUnitTests ????????????и? TEST_AFTER_BUILD ??????????
????????????????????????????? bundle ?????????????????????????????????κ??????????????????Щ????????? STAssert ????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11