如何模拟相机输入以进行浓缩咖啡测试?

时间:2019-01-09 16:58:02

标签: android testing android-espresso android-instrumentation

我在我的应用中使用相机进行条形码检测,我想编写浓缩咖啡测试。问题是我不知道如何在espresso中模拟相机,只有教程中介绍的是系统相机应用程序以意图启动,但是我有自己的相机源等。

有人对此有经验吗?

1 个答案:

答案 0 :(得分:0)

要使用espresso模拟自定义相机的意图,可以使用这种意图:

Intents.intending(IntentMatchers.hasComponent(YouCustomCameraView::class.java.name))
            .respondWith(ActivityResult(Activity.RESULT_OK, yourCustomIntent))

并将这种依赖性添加到您的gradle中,以使用意式浓缩咖啡和意式咖啡

 androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2')

因此,当您执行应启动YourCustomCameraView的单击时,它将直接为您提供此ActivityResult而不是您的CustomIntent。相机视图无法启动。