所以我创建了一个自定义抽象类,继承自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
}
}
如何对这些私有和内部函数进行单元测试?因为我无法从测试文件中访问这些函数。