How Does Swift Support Stubbing and Mocking? • Quality Coding

Mocks often make unit tests easier to write. They make communication contracts explicit in test code. But how do we do Swift mocking, when Swift is strict about types? The trick is to use Swift's protocols and extensions. I'll show you an example using URLSession.