Daily iOS
Testing

Testing an API-backed screen

This screen leans heavily on an API response. How would you change the code so you can test the screen, view model included, without a server request?

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

Abstract the network behind a protocol (a repository or service) that the view model takes in its initializer, and split the view so it only draws the view model's state. Then you can inject a stub implementation in tests.

Share a question