Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIControl';s sendActions不';在测试目标中不工作_Ios_Swift_Xctest_Xctestexpectation - Fatal编程技术网

Ios UIControl';s sendActions不';在测试目标中不工作

Ios UIControl';s sendActions不';在测试目标中不工作,ios,swift,xctest,xctestexpectation,Ios,Swift,Xctest,Xctestexpectation,我试图在调用UITextField发送editingChanged事件特殊处理程序时测试这一点。为此,我通过sendActions方法模拟了这个事件。但它在测试目标中不工作,只在项目中(运行模式-模拟器)一切正常 我写了一个小例子: class Strange { private let handler: () -> Void init(textField: UITextField, handler: @escaping () -> Void) {

我试图在调用
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()
    }
}
这里我想看到“test”打印,但在
sendActions
事件之后不会调用此处理程序。我也尝试了
期望值
,但对我没有帮助

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)
}

我做错了什么

在反应性可可库中找到了有趣的类别。 这对我有帮助!

我认为解决办法是。为我工作。