I'm working on a multi-module single activity application. Each feature module has its own navigation graph. I'm trying to navigate to a feature module from the another one using deep link as recommended in the official doc. (here)
When I run the app, there is no problem. Navigation with deeplink working well. But, when I try to test my fragment via testNavHostController gives error below:
Navigation destination that matches request NavDeepLinkRequest{ uri=android-app:/com.x.y/home } cannot be found in the navigation graph NavGraph(x_navigation)
x_navigation means my feature module's nav graph. I'm launching fragment by using Hilt-testing library for fragment isolation test.
launchFragmentInHiltContainer<F>(
fragmentArgs = fragmentArgs,
themeResId = themeResId,
) {
testNavHostController.setGraph(graphResId)
testNavHostController.setCurrentDestination(destinationId)
Navigation.setViewNavController(requireView(), testNavHostController)
}
AGP Version: 8.0
navigation-fragment-ktx Version: 2.5.3
I think that deep links are not loaded in fragment isolation test because the fragment is initialized in a container(HiltTestActivity) and it does not contain all navigation graphs like MainActivity. I tried to move all navigations to a single module like this.
However, It gave the runtime error as I expected (I think the reason was my AGP version).
If you link me about a sample code or share your experiences about this issue, I'll be greateful.
Have a nice day.
Tugce.