android - 如何模拟用于浓缩咖啡测试的相机输入?
问题描述
我在我的应用程序中使用相机进行条形码检测,我想编写浓缩咖啡测试。问题是我不知道如何在浓缩咖啡中模拟相机,教程中只介绍了系统相机应用程序,但我有自己的相机源等。
有人有这方面的经验吗?
解决方案
要使用 espresso 模拟自定义相机意图,您可以使用这种意图:
Intents.intending(IntentMatchers.hasComponent(YouCustomCameraView::class.java.name))
.respondWith(ActivityResult(Activity.RESULT_OK, yourCustomIntent))
并将此依赖项添加到您的 gradle 以使用带有 espresso 的意图模拟
androidTestImplementation('com.android.support.test.espresso:espresso-intents:2.2')
因此,当您执行应启动 YourCustomCameraView 的单击时,它将直接为您提供此 ActivityResult,而不是使用 yourCustomIntent。相机视图无法启动。
推荐阅读
- r - 列出目录中的图像,但排除子目录
- reactjs - Reactjs 不允许 dir="rtl" 显示文本 RTL
- javascript - 在对服务器的获取请求完成后,如何循环遍历数组并将信息添加到 firebase?
- c++ - 我如何将 Assimp 的纹理转换为 Unreal 引擎的 UTexture2D
- opengl - 使用 glBindAttribLocation() 的正确方法是什么?
- flutter - PageView.Builder 错误:附加到多个滚动视图的 ScrollController
- github - 使用 GitHub Actions 推送存储库时出错:接收 403
- c# - 指定要在批量合并(更新)时更新的属性
- flutter - 关闭应用程序时如何显示通知
- powerbi - 如何从 power bi 中具有相关行和列的表中创建这种(见下图)类型的视觉对象?