Automated tests for a user interface are typically performed in a separate process from the app, where they can be slow, brittle and complex. With appropriate support, many of these tests are better executed within the app as unit tests, where they’re easier and faster. UIUTest is a unit test library written in Swift for iOS, which allows many of the tests typically implemented as user interface tests with XCUIApplication to be written as unit tests within the application.
For more examples see: https://github.com/nallick/UIUTest_Examples