Daily iOS
Testing

Testing a playlist view model

A music app's playlist ViewModel takes a track list from a Repository and produces loading, success, and error states. How would you test those state transitions without a real network?

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

Through the initializer, inject a fake Repository that adopts the protocol so it returns success, failure, or an empty list at will, then await load() and compare the state enum against the case you expect.

Share a question