I am trying to test navigation with Espresso and Mockito. I'm using real device (Android 12) to see the results. With below code testing it gets stuck on the loading and not complete the test even after 10 minutes of waiting.
Then i wanted to run it with emulator (Pixel_API_32) and it worked. Do i miss something like some options or just it will not suppose to work on real device?
I searched for answer found this but didn't help. Can someone enlighten me?
@MediumTest
@HiltAndroidTest
@ExperimentalCoroutinesApi
class ShoppingFragmentTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Before
fun setup() {
hiltRule.inject()
}
@Test
fun clickAddShoppingItemButton_navigateToAddShoppingItemFragment() {
val navController = Mockito.mock(NavController::class.java)
launchFragmentInHiltContainer<ShoppingFragment> {
Navigation.setViewNavController(requireView(), navController)
}
Espresso.onView(withId(R.id.fabAddShoppingItem)).perform(click())
Mockito.verify(navController).navigate(
ShoppingFragmentDirections.actionShoppingFragmentToAddShoppingItemFragment()
)
}
}