test unit cellForRowAtIndexPath lors de l'utilisation de storyBoards

Si je déqueuse une cellule d'un identifiant dans un storyboard, comment puis-je appeler cellForRowAtIndexPath de manière unitaire et ne pas avoir la cellule nulle?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomCell]; cell.guestNameText.text = self.details.guestName; return cell; } 

Ne fonctionne pas, placez un point d'arrêt au-dessus après l'appel de dequeReusableCell et la cellule est nulle:

ETA: CODE DE TRAVAIL MIS À JOUR POUR PASSER LE TEST:

 - (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"); } 

Voici comment je teste les vues de table et leurs cellules. La key ici est d'appeler beginAppearanceTransition sur le controller de vue afin de le charger depuis le storyboard.

 class MyTests: XCTestCase { var viewController: UIViewController! override func setUp() { super.setUp() let storyboard = UIStoryboard(name: "MyStoryboard", bundle: nil) viewController = storyboard.instantiateViewControllerWithIdentifier("myViewControllerId") viewController.beginAppearanceTransition(true, animated: false) } override func tearDown() { super.tearDown() viewController.endAppearanceTransition() } func testShowItemsFromNetwork() { // // Load the table view here ... // let tableView = viewController.tableView // Check the number of table rows XCTAssertEqual(3, tableView.dataSource?.tableView(tableView, numberOfRowsInSection: 0)) // Check label text of the cell in the first row let indexPath = NSIndexPath(forRow: 0, inSection: 0) let cell = tableView.dataSource?.tableView(tableView, cellForRowAtIndexPath: indexPath) XCTAssertEqual("Test cell title", cell!.textLabel!.text) } }