XCTest waiting for expectation timeout does not trigger when using DispatchGroup

It might happen that when using DispatchGroup’s `wait` function the main thread could be blocked when testing.

Production code using DispatchGroup

Test without scheduling “execute“ on a different dispatch queue.

This is because the wait function inside the command’s `execute` would block the running queue until all the tasks inside the group are complete.

In order to solve this issue, we could schedule the tested function on a global dispatch queue inside the test to let the dispatch group finish when the scheduled tasks are complete. This would prevent the `DispatchGroup` to block the main thread and the test expectation could be successfully fulfilled.

Test scheduling execute function on a global dispatch queue.

Previous
Previous

Practical guide to manage developer certificates in your iOS team

Next
Next

How to do effective iOS developer meetings using Dependency Diagrams