【问题标题】:UIControl's sendActions doesn't work in Test targetUIControl 的 sendActions 在测试目标中不起作用
【发布时间】:2017-06-26 00:09:00
【问题描述】:

我正在尝试测试当UITextField 发送editingChanged 事件特殊处理程序被调用。因此,为此我通过sendActions 方法模拟此事件。但它在测试目标中不起作用,在项目中一切正常(运行模式 - 模拟器)。

我写了一个小例子:

class Strange {
    private let handler: () -> Void

    init(textField: UITextField, handler: @escaping () -> Void) {
        self.handler = handler
        textField.addTarget(self, action:#selector(textableValueChanged), for: .editingChanged)
    }

    @objc private func textableValueChanged() {
        handler()
    }
}

在这里我想看到“测试”打印,但是在sendActions 事件之后没有调用这个处理程序。我也试过expectation,但没有帮助。

func testStrangeBehaviour() {
    let expectation = self.expectation(description: "Bla-bla")
    s = Strange(textField: textfield1) {
        print("test")
        expectation.fulfill()
    }

    textfield1.sendActions(for: .editingChanged)
    waitForExpectations(timeout: 5, handler: nil)
}

我做错了什么?

【问题讨论】:

标签: ios swift xctest xctestexpectation


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多