DevPrep

All topics › Software architecture

How do you test a Presenter without UIKit?

Middle PRO

The point

A Presenter in MVP talks to the View through a protocol and to services through injected protocols. So in a test:

  1. instead of the View we inject a spy — a class that implements the protocol and records calls;
  2. instead of the service — a stub that returns a canned result;
  3. we call the Presenter's method and check what it told the View and with which data.

UIKit is not imported, no controller is created, no simulator is needed — the test runs in milliseconds and can run on a macOS host.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store