如何使用XCTestCase测试异步code [英] How to test async code using XCTestCase

查看:205
本文介绍了如何使用XCTestCase测试异步code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宁静的API的调用出来。我需要等待调用完成之前,我可以验证结果。 pretty共同的问题但我无法找到如何合并到XCTestCase这一个像样的答案。我所看到的信号量,锁,用于循环中的所有塞满了code运行应该是什么简单的例子。在X code 5运行IOS 7。

I have a call out to a restful API. I need to wait for the call to complete before I can validate the results. Pretty common problem yet I cannot find a decent answer on how to incorporate this into an XCTestCase. I have seen semaphores, locks, for loops all cluttering up code to run what should be a simple case. Running iOS 7 in xcode 5.

必须有一个更容易的选择。

There has to be an easier option.

推荐答案

您现在可以使用XCTestExpectation。在NSHipster教程可供选择: nshipster.com/xctestcase

You can now use XCTestExpectation. Tutorial available on NSHipster: nshipster.com/xctestcase

这篇关于如何使用XCTestCase测试异步code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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