My Test Code works with Navigation. But, click, type, etc events are not working. And also, the check() method isn't called.
I tried with running it inside runOnUiThread too. But still doesn't work. The login fragment is opened but no typing event causes.
How can I solve this issue?
My test code is below.
@RunWith(AndroidJUnit4::class)
@MediumTest
@ExperimentalCoroutinesApi
@HiltAndroidTest
class LoginFragmentTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)
@Before
fun init() {
hiltRule.inject()
}
@Test
fun test() {
launchFragmentInHiltContainer<LoginFragment>(null, R.style.ThemeDrugDelivery) {
// Create a NavController and set the NavController property on the fragment
assertNotNull(requireActivity())
val navController = TestNavHostController(requireActivity())
requireActivity().runOnUiThread {
navController.setGraph(R.navigation.nav_login)
}
Navigation.setViewNavController(requireView(), navController)
requireActivity().runOnUiThread {
onView(withId(R.id.acet_email)).perform(typeText("helloworld"))
onView(withId(R.id.acet_email)).check(matches(withText("helloworld")))
}
}
}
}