简体   繁体   中英

Testing with Espresso in Android error

I'm working with espresso for testing. I'm following Espresso Intents

and problem happened when I try to work like this site. First is validateIntentSentToPackage method:

public void validateIntentSentToPackage() {
    user.clickOnView(system.getView(R.id.callButton));
    intended(toPackage("com.android.phone"));}

Android Studio display error at "user" and "system". I don't understand this error what does this mean.

Second is activityResult_IsHandledProperly method:

public void activityResult_IsHandledProperly() {
    Intent resultData = new Intent();
    String phoneNumber = "123-345-6789";
    resultData.putExtra("phone", phoneNumber);
    ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultData);

    intending(toPackage("com.example.unittestdemo")).respondWith(result));
    onView(withId(R.id.pickButton)).perform(click());

    onView(withId(R.id.phoneNumber).check(matches(withText(phoneNumber)));}

Android Studio display error java.lang.NullPointerException and in line intending(toPackage("com.example.unittestdemo")).respondWith(result);

Please help!!!

Android Studio display error at "user" and "system". I don't understand this error what does this mean.

I guess, you don't have previously declared these variables.

I don't see any logs or whole code of this testing class, so I can only recommend you to check this example

Here you would find all methods which you're looking for in one file.

Also please visit Google Samples - Espresso Testing repository

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM