0
class MyClassVC: UIViewController {
var html : String?
var heightBar: CGFloat?
var webView: UIWebView?
override func viewDidLoad() {
super.viewDidLoad()
heightBar = self.navigationController?.navigationBar.frame.height
webView = UIWebView(frame: CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y, width: self.view.frame.width, height: self.view.frame.height - heightBar!))
let resources = NSBundle.mainBundle().pathForResource("example", ofType: "html")
let css = NSURL(fileURLWithPath: resources!)
webView!.loadHTMLString(html!, baseURL: css)
setNavBar()
self.view.addSubview(webView!)
}
func close(sender: UIBarButtonItem){
dismissViewControllerAnimated(true, completion: nil)
}
func setNavBar(){
var title : NSDictionary = Dictionary<NSObject,AnyObject>();
title = [NSFontAttributeName:UIFont.systemFontOfSize(20), NSForegroundColorAttributeName: UIColor(netHex: AppColors().getAppColors("colors"))]
self.navigationController!.navigationBar.titleTextAttributes = title as? [String : AnyObject]
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close", style: .Plain, target: self, action: #selector(MyClassVC.close(_:)))
}
}
我有上面的這個類,我需要爲這個類創建一個XCTestCase並使所有代碼覆蓋。 在XCTestCase中,我需要調用viewDidLoad(),close()和setNavBar()函數,如何正確地做到這一點?Swift(iOS)的代碼覆蓋率和XCTest(模擬)
是否有可能在swift中爲我的類使用模擬框架?如何做到這一點?
爲什麼你想嘲笑這個班? – dasdom