SwiftUI Testing: a Pragmatic Approach
<p>During the last few months, I’ve been reading “<a href="https://www.goodreads.com/en/book/show/48927138" rel="noopener ugc nofollow" target="_blank">Unit Testing Principles, Practices, and Patterns</a>” by <a href="https://twitter.com/vkhorikov" rel="noopener ugc nofollow" target="_blank">Vladimir Khorikov</a>. It’s definitely one of the best books I’ve read about testing. One of the things I’ve liked the most is that the author offers a “framework of reference” 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 “the four pillars of a good unit test”. 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’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>