1 year ago

#388552

test-img

Biggy Poopa

Testing Toast with Activity Scenario Rule

I am currently new to Android programming and I am trying to test parts of UI using espresso. Currently, I have a problem with a testing toast message.

Toast toast = Toast.makeText(context, R.string.some_message, duration);
toast.show();

And then in my test file, I define the Activity Scenario Rule.

public ActivityScenarioRule<CreateActivity> activityScenarioRule =
            new ActivityScenarioRule<>(SomeActivity.class);

At the end the best solution that I get for testing this part looks like this.

ActivityScenario<SomeActivity> scenario = activityScenarioRule.getScenario();
scenario.onActivity(activity ->
                Espresso.onView(ViewMatchers.withText(R.string.error_message)).inRoot(RootMatchers.withDecorView
                        (not(is(activity.getWindow().getDecorView())))).check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
);

When I run the test it never stops. Any help would be useful. :)

android

unit-testing

testing

android-espresso

toast

0 Answers

Your Answer

Accepted video resources