Very often, making code easy to unit test tends to go hand-in-hand
with improving that code’s separation of concerns, its state
management, and its overall architecture. In general, the more
well-abstracted and organized our code is, the easier it tends to be
to test it in an automated fashion.
However, in an effort to make code more testable, we can very often
find ourselves introducing a ton of new protocols and other kinds of
abstractions, and end up making our code significantly more
complicated in the process — especially when testing asynchronous
code that relies on some form of networking.
But does it really have to be that way? What if we could actually
make our code fully testable in a way that doesn’t require us to
introduce any new protocols, mocking types, or complicated
abstractions? Let’s explore how we could make use of Swift’s new
await capabilities to make that happen.