我正在为一个项目添加单元测试,并且正在为如何为 UITableViewCell 自定义类编写测试而磕磕绊绊。这是该类的代码:
class ConfirmSubmitTableViewCell: UITableViewCell, UICollectionViewDelegate {
var reportECTag: ReportECTag!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let photoArray = Utility.sharedInstance.getPhotoArray(reportECTag.fieldDataInformationDict)
return (photoArray.count)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let collectionCell = collectionView.dequeueReusableCellWithReuseIdentifier(kCollectionViewCell, forIndexPath: indexPath)
let imageView: UIImageView = collectionCell.viewWithTag(287) as! UIImageView
let photoArray = Utility.sharedInstance.getPhotoArray(reportECTag.fieldDataInformationDict)
imageView.image = UIImage(data: (photoArray.objectAtIndex(indexPath.row) as? NSData)!)//photoArray.objectAtIndex(indexPath.row) as? UIImage
return collectionCell
}
例如,我如何测试 awakeFromNib() 和 setSelected?
谢谢你。