{"id":16582,"date":"2016-12-09T16:45:15","date_gmt":"2016-12-09T21:45:15","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16582"},"modified":"2016-12-09T16:45:15","modified_gmt":"2016-12-09T21:45:15","slug":"how-to-unit-test-private-methods-in-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/12\/09\/how-to-unit-test-private-methods-in-swift\/","title":{"rendered":"How to Unit Test Private Methods in Swift"},"content":{"rendered":"<p><a href=\"https:\/\/cocoacasts.com\/how-to-unit-test-private-methods-in-swift\/\">Bart Jacobs<\/a>:<\/p>\n<blockquote cite=\"https:\/\/cocoacasts.com\/how-to-unit-test-private-methods-in-swift\/\">\n<p>While access control is a very welcome addition with many benefits, it can complicate unit testing, especially if you are new to unit testing. You probably know that you can apply the <code>testable<\/code> attribute to an import statement in a test target to gain access to entities that are declared as <strong>internal<\/strong>.<\/p>\n<p>While this is a convenient addition, it doesn&rsquo;t give you access to private entities in a test target.<\/p>\n<p>[&#8230;]<\/p>\n<p>The key takeaway of this article is that private entities don&rsquo;t need to be unit tested. Unit testing is a form of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Black-box_testing\">black-box testing<\/a>. This means that we don&rsquo;t test the implementation of the <code>AccountViewViewModel<\/code> struct, we test its specification.<\/p>\n<p>This doesn&rsquo;t mean that we are not interested in the implementation, though. We need to make sure the suite of unit tests covers every code path of the entity we are testing. Code coverage reports are invaluable to accomplish this.<\/p>\n<\/blockquote>\n<p>I don&rsquo;t find this very persuasive.<\/p>","protected":false},"excerpt":{"rendered":"<p>Bart Jacobs: While access control is a very welcome addition with many benefits, it can complicate unit testing, especially if you are new to unit testing. You probably know that you can apply the testable attribute to an import statement in a test target to gain access to entities that are declared as internal. While [&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":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","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":[46,71,901,268],"class_list":["post-16582","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language","tag-testing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16582","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=16582"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16582\/revisions"}],"predecessor-version":[{"id":16583,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16582\/revisions\/16583"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}