-
-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: NullPointerException while mocking NavController on instrumentation tests #355
Comments
Not sure about this one. Can you provide a sample project? Because it is pretty hard to deal with all this boilerplate project setup. |
Hi, I'm having the same issue with apollo client on instrumentation tests @oleksiyp you can check with apollo client
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
I should be able to mock NavController on a Espresso test.
Current Behavior
Im having this crash when I'm mocking NavController on a Espresso test:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object androidx.collection.SparseArrayCompat.get(int)' on a null object reference at androidx.navigation.NavGraph.findNode(NavGraph.java:171) at androidx.navigation.NavGraph.findNode(NavGraph.java:166) at androidx.navigation.ui.NavigationUI.findStartDestination(NavigationUI.java:570) at androidx.navigation.ui.AppBarConfiguration$Builder.<init>(AppBarConfiguration.java:124) at androidx.navigation.ui.ToolbarKt.setupWithNavController$default(Toolbar.kt:82)
Steps to Reproduce
Have a fragment with this the toolbar set up with NavControler:
val navController = findNavController() toolbar.setupWithNavController(navController)
Mock the Nav controller on the Espresso test:
private val navController :NavController = mockk(relaxed = true)
This should work with mockito, I didn't test it but google has a sample with it on their documentation:
https://developer.android.com/guide/navigation/navigation-testing
Context
Stack trace
The text was updated successfully, but these errors were encountered: