iphone - unit test cellForRowAtIndexPath when using storyBoards -


if i'm dequeuing cell identifier in storyboard, how in unit testing way can call cellforrowatindexpath , not have cell nil?

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      mycustomtableviewcell *cell = [tableview dequeuereusablecellwithidentifier:kcustomcell];      cell.guestnametext.text = self.details.guestname;      return cell; } 

not working, put break point above after dequereusablecell called , cell nil:

eta: updated working code pass 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 load view 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"); } 

here how test table views , cells. key here call beginappearancetransition on view controller in order load 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 table view here ...     //      let tableview = viewcontroller.tableview      // check number of table rows      xctassertequal(3, tableview.datasource?.tableview(tableview, numberofrowsinsection: 0))      // check label text of cell in first row      let indexpath = nsindexpath(forrow: 0, insection: 0)     let cell = tableview.datasource?.tableview(tableview, cellforrowatindexpath: indexpath)     xctassertequal("test cell title", cell!.textlabel!.text)   } } 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -