Kodeco Forums

Video Tutorial: Testing in iOS Part 2: Asynchronous Tasks & Mocks

Learn how to perform tests on your asynchronous code and how to use subclasses to make light weight mocks to tests parts of your iOS app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3493-testing-in-ios/lessons/3

Hello Greg, Nice video as usual, But i have a question. Is there is a way to test Asynchronous tasks without the delay option that you represented in this video. I don’t want to add time to the test method. I just want wait the code finish with it self, and when it’s finish, it continue running the code. Is there is a way to do that ?

I think you mean the timeout value rather than “delay”? It’s not actually a delay that makes your code run slower — it’s a timeout so that the test doesn’t wait around forever.

For example, if there’s a bug in your async task and it never completes, your test would wait forever and never complete. You can always set the timeout to 999999 or some large value, but I’d suggest a reasonable ceiling depending on what you’re testing. If you set a timeout of 10 seconds but your expectation is fulfilled in 0.5 seconds, then the test will take 0.5 seconds. Again, the 10 second value is just a maximum that ideally won’t be reached unless something has gone wrong.

OK, every thing is clear now, thank you Greg :slight_smile:

Hi Gregheo

Please suggest why we need the dispatch_sync while same thing can be achieved with the normal usage of function.

Thanks