MVVM+C: Making Navigation Testable and Scalable

No comments on MVVM+C: Making Navigation Testable and Scalable

Written by

in

AI helps us develop software faster, but faster changes also increase the risk of regressions. That makes strong automated test coverage even more important.

Navigation is one area where plain MVVM often becomes difficult to test.

The challenge with navigation in MVVM

In a traditional MVVM setup, the ViewController usually handles both UI and navigation: pushing the next screen, composing modules, handling deep links, and managing flow decisions.

Testing this through unit tests is difficult because the logic is tightly coupled to UIKit. As a result, navigation is often covered by UI tests.

UI tests work, but they can be slow, flaky, and expensive to maintain, which can significantly hurt the developer experience.

Moving navigation into a Coordinator

MVVM+C addresses this by moving navigation into a Coordinator.

The ViewController focuses on UI, while the Coordinator handles navigation, module composition, deep links, child flows, and flow completion.

MVVM + Coordinator architecture: AppCoordinator manages feature coordinators, with each module containing a ViewController and ViewModel.

With navigation dependencies abstracted behind testable interfaces, this makes navigation decisions easier to cover with fast, reliable unit tests. UI tests can then focus on a small number of critical end-to-end scenarios.

Scaling across features and teams

Another benefit is loose coupling between modules. Each feature can own its own MVVM+C flow, which makes the architecture easier to scale across teams.

MVVM+C is not just about cleaner navigation. It makes navigation isolated, scalable, and testable.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *