如何在Swift中对计算属性进行单元测试?

时间:2020-06-22 11:41:24

标签: swift unit-testing computed-properties guard-statement

如何迅速对计算属性的保护声明进行单元测试?

运行单元测试时,代码覆盖范围中不包含fataError行。

有什么方法可以测试计算出的属性?

class HomePresenter: HomeViewToPresenterProtocol {

    var view: HomePresenterToViewProtocol?
    var router: HomePresenterToRouterProtocol?
    var interactor: HomePresentorToInterectorProtocol?

    var homeView: UIViewController {
        guard let view = view as? UIViewController else {
            fatalError("View cannot be casted as UIViewController")
        }
        return view
    }

    init(view: HomePresenterToViewProtocol, interactor: HomePresentorToInterectorProtocol, router: HomePresenterToRouterProtocol) {
        self.view = view
        self.interactor = interactor
        self.router = router
    }

}

0 个答案:

没有答案