【发布时间】:2018-01-17 08:25:44
【问题描述】:
所以我创建了一个自定义的抽象类,它继承自 UIViewController(由 RebloodViewController 继承)名为 MainViewController 的类。在这个类中我写了一个可重用的 nib 注册函数
class MainViewController: RebloodViewController {
typealias Cell = RebloodViewController.Constants.Cell
internal func registerNib(_ cellNib: Cell.Nib, target: UICollectionView) {
let nib = UINib(nibName: cellNib.rawValue, bundle: nil)
do {
let identifier = try getCellIdentifierByNib(cellNib)
target.register(nib, forCellWithReuseIdentifier: identifier)
} catch {
fatalError("Cell identifier not found from given nib")
}
}
private func getCellIdentifierByNib(_ nib: Cell.Nib) throws -> String {
var identifier: String? = nil
switch nib {
case .articles:
identifier = Cell.Identifier.articles.rawValue
case .events:
identifier = Cell.Identifier.events.rawValue
}
guard let CellIdentifier = identifier else {
throw MainError.cellIdentifierNotFound
}
return CellIdentifier
}
}
对这些私有和内部函数进行单元测试的最佳方法是什么?因为我无法访问测试文件中的函数。
【问题讨论】:
-
这个问题的答案里有说明stackoverflow.com/questions/48208241/…
标签: ios swift unit-testing nib