IOS UITest 初始化 ViewController
import XCTest @testable import UITestDemo class UITestDemoTests: XCTestCase { var homevc:HomeViewController? ; override func setUp() { super.setUp() // let sb=UIStoryboard.init(name: "Main", bundle: nil); homevc = sb.instantiateViewControllerWithIdentifier("homeVC") as? HomeViewController; homevc?.loadView();//初始化viewController } override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } func testExample() { homevc!.ClickBtnSubmit("");//触发发点击事件 XCTAssertEqual(homevc!.tfName.text ,"y");//断言文本框内的值是y }
主要是 下面这句. 这样就可以测试controller里的大部分逻辑了.
homevc?.loadView();//初始化viewController