mercredi 8 avril 2015

How to unit test cell from storyboard

I want to check if a cell (storyboard!) fulfills certain requirements (like has certain properties etc.) But I do not seem to be able to instantiate it from the storyboard.



override func setUp() {
tableView = UITableView()
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))
viewController = storyboard.instantiateViewControllerWithIdentifier("tvcStorageList") as? tvcStorageList
let x = viewController.view
navController = MockNavigationController(rootViewController: viewController)
successMockDBDidReplaceProductDB = substituteWithMockDatabase()
viewController.viewDidLoad()
}


func testCorrectTableCellIsReturned() {
viewController.viewDidLoad()
let cell = viewController.tableView(tableView, cellForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 0))
println(cell)
}


// the table....



override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("StorageCell") as! Storage2TableViewCell

let row = indexPath.row
let temp = storageList[row]
let thisStorage = temp
cell.name.text = temp.name


Trying to test a get a bad access where the cell should be dequeued.


Aucun commentaire:

Enregistrer un commentaire