0

我正在为 iOS 编写单元测试。有没有办法模拟平移或缩放等手势?我想在视图上模拟这些手势,然后验证结果。

4

2 回答 2

0

您应该使用自动化测试框架进行涉及视图、视图控制器和手势的测试。示例包括UIAutomationKIFCalabash

于 2013-09-09T19:58:15.090 回答
0

You can use presenter pattern where you have a presenter for the controller and all controller does is on receiving the gesture, it asks presenter to do all the work it has to do. Then you can unittest the presenter.

Here is one simple example for presenter in swift for touchup on button

Controller:

Class myController: UiViewController, MyView {
    var presenter: MyPresenter!
    @IBAction func buttonPressed(sender: AnyObject) {
            presenter.buttonPressed()
    }
    override func viewDidLoad {
         super.viewDidLoad()
         self.presenter = MyPresenter(view: self) 
    }
}

Presenter:

Class MyPresenter {
    init(view: MyView) {
        self.myView = view
    }
    func buttonPressed() {
         //code to be tested
    }
}

Protocol:

protocol MyView {
    //methods for presenter to communicate with view controller
}
于 2015-09-02T10:58:22.870 回答