问题
I have used third party library in my sign up form for selecting image from gallery. My signup form works fine. Now I want to test it using espresso.The biggest problem that I am facing right now is how to set profile photo's imageview while testing ?
回答1:
You should use espresso-intents to detect that intent from the camera roll and set a picture.
Here you have the method I use:
public static void simulatePictureFromCameraRoll(Uri pictureUri) throws Exception {
Exception returnException = null;
Intent resultData = new Intent();
resultData.setData(pictureUri);
Intents.init();
try {
Matcher<Intent> expectedIntent = hasAction(Intent.ACTION_GET_CONTENT);
intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData));
onView(withId(R.id.lytProfImageChooseFromLibrary)).perform(click());
intended(expectedIntent);
}
catch (Exception e) {
returnException = e;
}
finally {
Intents.release();
}
if (returnException != null) {
throw returnException;
}
}
Hope this helps.
来源:https://stackoverflow.com/questions/38651068/how-to-set-image-in-imageview-while-testing-with-espresso