【发布时间】:2018-01-07 01:37:26
【问题描述】:
我对 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() {
}
}
【问题讨论】:
-
为什么要使用单元测试来测试 UI 和查看控制器演示?您可以对此类事情使用 UI 测试。
-
就像我说的,我对测试很陌生。不过,您的意见很有帮助,谢谢!
标签: ios swift uiviewcontroller xctestcase