mercredi 8 juillet 2020

Espresso test to check if dialer matches number

Hi trying to test that a call button opens the dialler and 999 appears. Have followed answers on here but still getting the same error

DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.

Here is my code that I am using from an example on here, thanks

@RunWith(AndroidJUnit4.class)
public class EmergencyCallTest {
    @Rule
    public ActivityTestRule<CallActivity> mCallActivityTestRule
            = new ActivityTestRule<>(CallActivity.class, true, true);

    //Test to check if clicking call button launches the phone dialler
    @Test
    public void clickCallButton_opensDialler_forAmbulance() {

      //  onView(withId(R.id.call_ambulance_btn)).perform(click());
        //intended(Matchers.allOf(hasAction(Intent.ACTION_DIAL),hasData(Uri.parse("tel+:999"))));



        Intent stubIntent = new Intent();
        Instrumentation.ActivityResult stubResult = new Instrumentation.ActivityResult(Activity.RESULT_OK, stubIntent);

        intending(hasAction(Intent.ACTION_DIAL)).respondWith(stubResult);
        onView(withId(R.id.call_ambulance_btn)).perform(click());
        intended(Matchers.allOf(hasAction(Intent.ACTION_DIAL), hasData(Uri.parse("tel:+999"))));
    }

    @Before
    public void setUp() {
        // start recording intents before activity launch
        Intents.init();
    }

    @After
    public void cleanUp() {
        // clears out all recorded intents after test completes
        Intents.release();
    }

}

Aucun commentaire:

Enregistrer un commentaire