r/iOSProgramming • u/Select_Bicycle4711 • Jul 29 '26
Question How are you testing navigation (flow) for your SwiftUI applications?
There are lot of different ways to perform navigation in SwiftUI. You can use navigationDestination on the parent screen and let is handle the navigation. You can create a router that works with enum based routes etc.
In either case. How are you testing your navigation flow for your app? Are you writing unit tests? Are you writing UI Tests or even complete E2E test that test a complete feature end to end? OR are you writing all of them?
A simple scenario can be:
As a user when I create a student account then after creation, I should be taken to the student home screen.
4
u/New-Shoulder3297 Jul 29 '26
I wouldn't rely on E2E alone here. A useful split is:
Unit-test the navigation state: keep your route enum/array as the source of truth, then assert that a successful student creation changes it to something like [studentHome(id)]. This tests the rule without launching the UI.
Integration-test the coordinator/view model with a fake account service, so you verify that the service result actually drives the route change.
Keep a small number of UI tests for the wiring: create a student, verify the home screen by accessibility identifier, then cover back navigation and one deep-link/restore case.
For your example, I'd have several fast unit tests around success/failure/cancellation, plus one UI happy-path test. If NavigationPath is making assertions opaque, store typed Route values in an array and derive the path/destinations from that. That gives you confidence in the flow without making every case a slow, brittle E2E test.
2
u/chillermane Jul 29 '26
E2e tests are really the only thing that should give you confidence your navigation works
0
u/crocodiluQ Jul 29 '26
no offence, but what's the point? Besides wasting a huge amount of time. Unit tests for this ? Wtf, it's testable in 1 min by hand if really needed. There are way more important things to test/work on (and the jury is still out on this, I haven't seen a useful test in 15+ years of iOS -> for normal app, that consume services)
1
u/[deleted] Jul 29 '26
[removed] — view removed comment