SwiftUI Testing: a Pragmatic Approach

<p>During the last few months, I&rsquo;ve been reading &ldquo;<a href="https://www.goodreads.com/en/book/show/48927138" rel="noopener ugc nofollow" target="_blank">Unit Testing Principles, Practices, and Patterns</a>&rdquo; by&nbsp;<a href="https://twitter.com/vkhorikov" rel="noopener ugc nofollow" target="_blank">Vladimir Khorikov</a>. It&rsquo;s definitely one of the best books I&rsquo;ve read about testing. One of the things I&rsquo;ve liked the most is that the author offers a &ldquo;framework of reference&rdquo; to analyze how good a test is based on the following traits:</p> <ul> <li>Protection against regressions.</li> <li>Resistance to refactoring.</li> <li>Fast feedback.</li> <li>Maintainability.</li> </ul> <p>Those traits are what the author calls &ldquo;the four pillars of a good unit test&rdquo;. And the interesting part is that we cannot maximize all of them. Some types of tests provide the best protection against regression and resistance to refactoring but with very slow feedback (like UI testing). At the end of the day, we have to think and decide the best trade-offs for our specific application and use cases.</p> <p>I&rsquo;ve been thinking a lot about this and how to apply that framework to improve my testing, especially applied to the view layer, where things are especially tricky. And more specifically to SwiftUI, where we are still rethinking good practices and patterns to better fit this new exciting platform.</p> <p><strong><a href="https://betterprogramming.pub/swiftui-testing-a-pragmatic-approach-aeb832107fe7">Visit Now</a></strong></p>