{"id":39053,"date":"2023-04-13T15:02:37","date_gmt":"2023-04-13T19:02:37","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=39053"},"modified":"2023-04-13T15:02:37","modified_gmt":"2023-04-13T19:02:37","slug":"casting-in-xctest-methods","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/04\/13\/casting-in-xctest-methods\/","title":{"rendered":"Casting in XCTest Methods"},"content":{"rendered":"<p><a href=\"https:\/\/paul-samuels.com\/blog\/2023\/03\/23\/xctcast\/\">Paul Samuels<\/a>:<\/p>\n<blockquote cite=\"https:\/\/paul-samuels.com\/blog\/2023\/03\/23\/xctcast\/\"><p>The XCTest framework added the super helpful function <code>XCTUnwrap<\/code> back in Xcode 11.\nAt the time I added a similar helper to my various projects to help smooth over the many cases where casting is required.\nThe idea is to have a similar call site to <code>XCTUnwrap<\/code> but for use in situations where you want to verify you have the right type or fail.<\/p><\/blockquote>\n<p>His example also demonstrates using the new <code>record(_ issue: XCTIssue)<\/code> method, which lets you provide more information than just failing with a string description.<\/p>\n<p>I added casting to my tests around the time I <a href=\"https:\/\/mjtsai.com\/blog\/2017\/02\/24\/let-your-swift-xctest-methods-throw\/\">added unwrapping<\/a> and find it very helpful. And you can often use type inference to avoid having to pass in the type.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/03\/16\/passing-types-to-swift-functions\/\">Passing Types to Swift Functions<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2017\/02\/24\/let-your-swift-xctest-methods-throw\/\">Let Your Swift XCTest Methods Throw<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Paul Samuels: The XCTest framework added the super helpful function XCTUnwrap back in Xcode 11. At the time I added a similar helper to my various projects to help smooth over the many cases where casting is required. The idea is to have a similar call site to XCTUnwrap but for use in situations where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-04-13T19:02:40Z","apple_news_api_id":"e09c3c60-3bcc-4af5-ae1b-7c3d3159a6a1","apple_news_api_modified_at":"2023-04-13T19:02:40Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A4Jw8YDvMSvWuG3w9MVmmoQ","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":[30,2223,71,901,268,226],"class_list":["post-39053","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-mac","tag-macos-13-ventura","tag-programming","tag-swift-programming-language","tag-testing","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39053","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=39053"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39053\/revisions"}],"predecessor-version":[{"id":39054,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/39053\/revisions\/39054"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=39053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=39053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=39053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}