{"id":42590,"date":"2024-03-21T16:25:33","date_gmt":"2024-03-21T20:25:33","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=42590"},"modified":"2024-03-21T16:25:33","modified_gmt":"2024-03-21T20:25:33","slug":"how-to-bypass-swiftui-app-launch-during-unit-testing","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/03\/21\/how-to-bypass-swiftui-app-launch-during-unit-testing\/","title":{"rendered":"How to Bypass SwiftUI App Launch During Unit Testing"},"content":{"rendered":"<p><a href=\"https:\/\/qualitycoding.org\/bypass-swiftui-app-launch-unit-testing\/\">Jon Reid<\/a>:<\/p>\n<blockquote cite=\"https:\/\/qualitycoding.org\/bypass-swiftui-app-launch-unit-testing\/\"><p>For apps with an application delegate, I&rsquo;ve written <a href=\"https:\/\/qualitycoding.org\/ios-app-delegate-testing\/\">How To Switch Your iOS App Delegate for Improved Testing<\/a>. 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 <code>@main<\/code>? Yes, we can.<\/p><p>[&#8230;]<\/p><p>Basically, this conditional says, &ldquo;Let&rsquo;s make sure we&rsquo;re running the production app. If we are, great, show the content. If not, leave the view hierarchy empty.&rdquo;<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Jon Reid: For apps with an application delegate, I&rsquo;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.[&#8230;]Basically, this conditional [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-03-21T20:25:35Z","apple_news_api_id":"1669744d-3a43-41f1-aae2-37d75c3a9e2b","apple_news_api_modified_at":"2024-03-21T20:25:35Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AFml0TTpDQfGq4jfXXDqeKw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2321,71,901,1812,268,226],"class_list":["post-42590","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-17","tag-programming","tag-swift-programming-language","tag-swiftui","tag-testing","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=42590"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42590\/revisions"}],"predecessor-version":[{"id":42591,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42590\/revisions\/42591"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=42590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=42590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=42590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}