I have app with mvvm architecture and single activity pattern. I am using jetpack navigation component. Now I want to make end to end test with espresso. I want to test this scenario. User fill all data in login page and click sign in button after app navigate to new screen and fills data in new screen.Here a simple example of my code.
@RunWith(AndroidJUnit4::class)
@MediumTest
@ExperimentalCoroutinesApi
@HiltAndroidTest
class PhoneNumberFragmentTest {
@Rule
@JvmField
val hiltRule = HiltAndroidRule(this)
private val navController = TestNavHostController(ApplicationProvider.getApplicationContext())
@Before
fun setUp() {
hiltRule.inject()
}
@Test
fun check_is_view_available_in_screen(){
launchFragment<PhoneNumberFragment>(R.id.phoneNumberFragment,null, navController = navController)
onView(withId(R.id.registerTitle)).check(matches(isDisplayed()))
onView(withId(R.id.registerDescription)).check(matches(isDisplayed()))
onView(withId(R.id.constraintPhoneNumber)).check(matches(isDisplayed()))
onView(withId(R.id.sendOtpButton)).check(matches(isDisplayed()))
onView(withId(R.id.agreeCheckBox)).check(matches(isDisplayed()))
onView(withId(R.id.agreeCheckBox)).check(matches(isChecked()))
onView(withId(R.id.sendOtpButton)).check(matches(not(isEnabled())))
onView(withId(R.id.phoneNumber)).perform(typeText("940711242"))
onView(withId(R.id.sendOtpButton)).perform(click())
}
}
Now here problem is I can't check is navigation successfully and can't check data in new screen is displayed.