不了解XCTestExpectations的单元测试异步UI代码? [英] Unit testing asychronous UI code which does not know about XCTestExpectations?

查看:55
本文介绍了不了解XCTestExpectations的单元测试异步UI代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对在非平凡的图形设置中工作的iOS代码进行单元测试?

考虑实例视图控制器 A B ,其中 A 在顶部将 B performSegueWithIdentifier:sender:.单元测试应检查 C 的行为,该行为取决于像这样排列的两个视图控制器.

performSegueWithIdentifier:sender:是异步工作的,即,除非让单元测试等待诸如 XCTestExpectation 之类的内容,否则单元测试将在完成其任务之前结束.但是在这样的情况下, B C 都没有准备在这种期望下调用 fulfill .

在这样的情况下是否有前进的方法,即测试异步UI代码而没有用于调用 fulfill 的现成钩子?

我得出结论,采用集成测试框架(例如KIF)可能是可行的方法.

How can one go about unit-testing pieces of iOS code that work in a non-trivial graphical setup?

Consider for instance view controllers A and B, where A stacks B on top with performSegueWithIdentifier:sender:. A unit test should check the behavior of a C that depends on the two view controllers being arranged like that.

performSegueWithIdentifier:sender: works asynchronously, i.e. the unit test would end before it has completed its task unless one lets the unit test wait for something like an XCTestExpectation. But in a case like this neither B nor C is prepared to call fulfill on that expectation.

Is there a way forward in situations like this, i.e. for testing asynchronous UI code without ready hooks for calling fulfill?

解决方案

I have concluded that employing an integration test framework (such as KIF) is probably the way to go.

这篇关于不了解XCTestExpectations的单元测试异步UI代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆