Thursday, March 21, 2024

How to Bypass SwiftUI App Launch During Unit Testing

Jon Reid:

For apps with an application delegate, I’ve written How To Switch Your iOS App Delegate for Improved Testing. This lets us set up a separate launch sequence for test runs that does only the bare minimum. Can we do the same thing for SwiftUI apps that use @main? Yes, we can.

[…]

Basically, this conditional says, “Let’s make sure we’re running the production app. If we are, great, show the content. If not, leave the view hierarchy empty.”

Comments RSS · Twitter · Mastodon

Leave a Comment