lundi 24 juin 2019

Android Kotlin Espresso Mockito Test and verify Navigation Controller of a fragment navigates to 2 conditional fragments as a destination

In my app, I am testing navigational components using navigation controller using Kotlin lang, Espresso framework and using Mockito. App has multiple fragments. Few tests are running fine. But not able work with following scenerio

There is fragment supposed name fragment2, fragment2 navigates to fragment3 and fragment4 according to condition what input user provide in fragment2

Just want to understand how it will work. Providing my code below for another test which is running fine for fragment4 to fragment2(where fragment 4 always redirects tofragment 2, i.e single navigation)

  @Test
fun testNavigationFromGameOverToGameFragment() {
    // Create a mock NavController
    val mockNavController = mock(NavController::class.java)

    // Create a graphical FragmentScenario for the TitleScreen
    val gameOver = launchFragmentInContainer<GameOverFragment>(themeResId 
= R.style.AppTheme)

    // Set the NavController property on the fragment
    gameOver.onFragment { fragment ->
        Navigation.setViewNavController(fragment.requireView(), 
mockNavController)
    }

    // Verify that performing a click prompts the correct Navigation 
action

onView(ViewMatchers.withId(R.id.tryAgainButton)).perform(ViewActions.click())

verify(mockNavController).navigate(R.id.action_gameOverFragment_to_gameFragment) }

I want approach for the same

Aucun commentaire:

Enregistrer un commentaire