不了解XCTestExpectations的单元测试异步UI代码? [英] Unit testing asychronous UI code which does not know about XCTestExpectations?
问题描述
如何对在非平凡的图形设置中工作的iOS代码进行单元测试?
考虑实例视图控制器 A
和 B
,其中 A
在顶部将 B
与performSegueWithIdentifier:sender:
.单元测试应检查 C
的行为,该行为取决于像这样排列的两个视图控制器.
performSegueWithIdentifier:sender:
是异步工作的,即,除非让单元测试等待诸如 XCTestExpectation
之类的内容,否则单元测试将在完成其任务之前结束.但是在这样的情况下, B
和 C
都没有准备在这种期望下调用 fulfill
.
在这样的情况下是否有前进的方法,即测试异步UI代码而没有用于调用 fulfill
的现成钩子?
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屋!