4
스토리 보드의 식별자에서 셀을 dequeuing하는 경우 단위 테스트 방법에서 cellForRowAtIndexPath를 호출하고 셀을 0으로 만들지 못하는 이유는 무엇입니까?storyBoard를 사용할 때 단위 테스트 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCell];
cell.guestNameText.text = self.details.guestName;
return cell;
}
작동하지 않는, dequeReusableCell가 호출되고 세포는 전무 후 위의 중단 점을 넣어 :
는 ETA : 업데이트] WORKING 코드가 시험을 통과 : 여기
- (void)setUp {
[super setUp];
_detailVC_SUT = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:kDetailsVC];
_myService = [OCMockObject niceMockForClass:[MyService class]];
_detailVC_SUT.service = _myService;
}
- (void)test_queryForDetailsSucceeded_should_set_cell_text_fields {
[_detailVC_SUT view]; // <--- Need to load the view for this to work
Details *details = [DetailsBuilder buildStubDetails];
[_detailVC_SUT queryForDetailsSucceededWithDetails:details];
[self getFirstCellForGuestName];
}
- (void)getFirstCellForGuestName {
MyCustomTableViewCell *guestNameCell = (MyCustomTableViewCell*)[_detailVC_SUT tableView:_detailVC_SUT.detailsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
expect(guestNameCell.guestNameText.text).to.equal(@"Mark");
}
테스트에서보기가 실제로로드됩니까? – Wain
예, [_detailVC_SUT 뷰]를 추가했습니다. 하지만 여전히 손님을 위해 아무 것도 보여주지 않습니다. 셀. 완전한 코드 –
으로 업데이트되었습니다. 뷰를 불러 오기 위해 뷰를 호출 한 후 작동합니다. 누락되었습니다. 그러나 이제는 작동합니다. 제안에 감사드립니다. Wain! –