Flutter GoRouter testing strategy for complex navigation using getIt and mocktail
Iβve authored a comprehensive guide on building a scalable Flutter app, [available here]. In its fourth section [available here], I delve into the intricacies of complex navigation using GoRouter and provide insights into testing your app, including coverage for URL navigation and redirection.
I believe this specific aspect is noteworthy enough to warrant a dedicated, condensed article.
GoRouter stands out as a potent declarative routing solution for Flutter. Leveraging a router represents the most advanced approach to fully capitalize on Navigator 2.0, effortlessly supporting deep links, URL navigation, and redirection. GoRouter significantly simplifies the utilization of the Navigator 2.0 API.
However, when it comes to documenting unit tests, some scenarios may not have an immediately obvious approach.
Consider the following route graph for illustration:
ROUTER CONFIG
|
|---DefaultRoute
| Path: "/"
| Redirect (always): "/articles"
|
|---HomeView (StatefulShellRoute)
|
|---Branch 0
| |
| |---ArticleList
| | Path: "/articles?articleId=[articleId]"
| |
| |---ArticleDetails
| Path: "/articles/:articleId"
|β¦