tezvyn:

Making a Legacy UIViewController Testable

Source: interviewintermediate

WHAT IT TESTS: refactoring legacy UIKit for testability. OUTLINE: extract logic into a testable view model, inject dependencies, keep the controller a thin humble object. RED FLAG: rewriting everything at once or testing through the UIKit lifecycle directly.

WHAT IT TESTS: pragmatic refactoring of untestable Massive View Controllers. ANSWER OUTLINE: incrementally extract business and presentation logic into a UIKit-free view model that exposes plain state and methods, inject its dependencies behind protocols so they can be mocked, and reduce the controller to a Humble Object that only forwards inputs and renders outputs. Add characterization tests first to lock current behavior. RED FLAG: a big-bang rewrite, or trying to unit test logic still buried inside viewDidLoad.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Making a Legacy UIViewController Testable · Tezvyn