Daily iOS
Testing

Mocking the network

You want to test a network layer that uses URLSession directly, with no real server. Can you give me at least two ways to do it?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

You can abstract the session behind a protocol and inject a stub, or register a URLProtocol subclass on URLSessionConfiguration to intercept the real URLSession path.

Share a question