我对 iOS 开发人员非常陌生,我正在尝试为一个类编写一个单元测试用例。它只有一个名为 homeButtonTouched() 的方法,可以通过动画关闭视图控制器。我该如何为此编写单元测试?这就是班级的样子。
class AboutViewController: UIViewController {
// MARK: Action
@IBAction func homeButtonTouched(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
}
}
这是我到目前为止在我的测试课上写的。我只需要填写 testHomeButtonTouched() 方法。
class AboutViewControllerTests: XCTestCase {
var aboutViewController: AboutViewController!
override func setUp() {
aboutViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "About View Controller") as! AboutViewController
aboutViewController.loadView()
super.setUp()
}
override func tearDown() {
aboutViewController = nil
super.tearDown()
}
/** Test that pressing the home button dismisses the view controller */
func testHomeButtonTouched() {
}
}