https://kotlinlang.org logo
#android
Title
# android
j

Joan Colmenero

04/28/2020, 10:50 PM
Hi, how do I test an extension function of a Toast or Progressbar?
j

Joan Colmenero

04/29/2020, 9:42 AM
But I just want to test that a toast extension function is working
I have something like
Copy code
Context.showToast(@StringRes ....){Toast....})
n

Nikhil

04/29/2020, 2:28 PM
You can use assertThat. We actually can now test for toast messages using robolectric. The example below is how our team is doing this for now: @Test public void ccButtonDisplaysToast() throws NullPointerException { Button ccRedButton = (Button) findViewById(R.id.cc_red); cc_red.performClick(); --> this calls the actual onClickListener implementation which has the toast. ShadowLooper.idleMainLooper(YOUR_TIME_HERE); --> This may help you. assertThat(ShadowToast.getTextOfLatestToast().toString(), equalTo("TEST_YOUR_TEXT_HERE")); } Hope this helps
2 Views