使用espresso测试时如何在imageview中设置图像? [英] How to set image in imageview while testing with espresso?

查看:100
本文介绍了使用espresso测试时如何在imageview中设置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在注册表格中使用了第三方库来从图库中选择图像.我的注册表单工作正常.现在我要使用espresso进行测试.我现在面临的最大问题是如何在测试时设置个人资料照片的imageview?

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 ?

推荐答案

您应使用咖啡意向,以从相机胶卷中检测到该意向并设置图片.

You should use espresso-intents to detect that intent from the camera roll and set a picture.

这里有我使用的方法:

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;
    }
}

希望这会有所帮助.

这篇关于使用espresso测试时如何在imageview中设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆