Testing UIKit
It is possible to unit test UIKit components. It’s annoying and in a lot of places undocumented. However, in my experience, it is significantly faster and more reliable to test UI from what xcode describes as a unit test perspective vs. using XCUITest
.
As far as this document is concerned, a unit-testing perspective means that the tests run in the same process the code being tested runs in. For example, in a UI Testing Bundle, there are 2 separate processes running: The app itself is running in one process, and the tests are running in a second process. They communicate via IPC.
-
Most APIs work fine without being in a window hierarchy.
- The main exception here is the
UIViewController
presentation APIs, such as: - Additionally, most of the standard ViewController containers also need to be inside of window hierarchies, such as:
- The main exception here is the
-
A lot of views work just fine when they are size 0. Views that don’t work fine include:
UITableView
(if you access thevisibleCells
and related apis)UICollectionView
(if you access thevisibleCells
and related apis)
Last updated: 2021-11-14 22:08:54 -0800