{"id":40774,"date":"2023-10-11T17:21:17","date_gmt":"2023-10-11T21:21:17","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=40774"},"modified":"2023-10-11T17:21:17","modified_gmt":"2023-10-11T21:21:17","slug":"unit-testing-a-swiftui-query","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/10\/11\/unit-testing-a-swiftui-query\/","title":{"rendered":"Unit Testing a SwiftUI Query"},"content":{"rendered":"<p><a href=\"https:\/\/mastodon.social\/@helge\/110905899267242986\">Helge He&szlig;<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@helge\/110905899267242986\"><p>I&rsquo;ve been wondering whether I could unit test a SwiftData <code>Query<\/code>, i.e. the SwiftUI property wrapper coming w\/ SwiftData (in beta6 it is actually a macro). Aka whether I could unit test a SwiftUI view. This requires setting up an execution environment for the view, but surprisingly that actually works &#x1F642;<\/p><\/blockquote>\n<p>Here&rsquo;s the <a href=\"https:\/\/gist.github.com\/helje5\/dfaafc29fc0e081756fadfacc7b0076a\">gist<\/a>.<\/p>\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/12\/swiftdata\/\">SwiftData<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/01\/26\/swiftui-unit-testing\/\">SwiftUI Unit Testing<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Helge He&szlig;: I&rsquo;ve been wondering whether I could unit test a SwiftData Query, i.e. the SwiftUI property wrapper coming w\/ SwiftData (in beta6 it is actually a macro). Aka whether I could unit test a SwiftUI view. This requires setting up an execution environment for the view, but surprisingly that actually works &#x1F642; Here&rsquo;s the [&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":"2023-10-11T21:21:19Z","apple_news_api_id":"04a40427-be8b-459e-b8f4-2ff6a7a57f9d","apple_news_api_modified_at":"2023-10-11T21:21:20Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ABKQEJ76LRZ649C_2p6V_nQ","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,30,2385,74,71,901,2404,1812,268],"class_list":["post-40774","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-17","tag-mac","tag-macos-14-sonoma","tag-opensource","tag-programming","tag-swift-programming-language","tag-swiftdata","tag-swiftui","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40774","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=40774"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40774\/revisions"}],"predecessor-version":[{"id":40775,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40774\/revisions\/40775"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=40774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=40774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=40774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}