Testing Snackbar show with Espresso

前端 未结 3 1572
陌清茗
陌清茗 2021-02-05 00:28

Is there a way to test using Espresso that the snackbar shows up with the right text?

I have a simple call to create a snackbar

Snackbar.make(mView, \"My         


        
3条回答
  •  难免孤独
    2021-02-05 01:13

    I saw the previous answers but I thought this would be better.

    @Test
    public void onFabClick_shouldDisplaySnackbar() throws Exception {
      onView(withId(R.id.fab)).perform(click());
    
      // Compare with the text message of snackbar
      onView(withText(R.string.snackbar_message))
          .check(matches(isDisplayed()));
    }
    

提交回复
热议问题