android - 在 Android 测试中模拟 FingerprintManager

标签 android unit-testing junit android-fingerprint-api

有没有办法模拟或模拟FingerprintManager.authenticate() ?我想为我的指纹验证器编写仪器化测试。

如果有一个解决方案限制测试可以在模拟器或设备上运行,我很好。我使用 JUnit 4.12。

最佳答案

本着 not mocking things you don't own 的精神,我可能会建议您不要 mock 它.我可能会建议什么(来自上面的链接):

The prescription implied by "don't mock what you don't own" is to introduce your own shim/wrapper/adapter around it. This effectively cordons off the dependency to a single place in your codebase and contextualizes it in the consistent and easy-to-use style you're trying to promote within your codebase. If there's anything awkward about how one needs to invoke the dependency (maybe a chaining API, multi-step invocation, repetitive default configuration, etc.), it can be swept under the rug into that common adapter.

这感觉像是 humble object pattern可能是合适的。

关于android - 在 Android 测试中模拟 FingerprintManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46053100/

相关文章:

android - 如何在不使用应用程序登录按钮的情况下通过 facebook android sdk 共享照片

java - 我应该为简单地构建和返回数据结构的函数编写单元测试吗?

java - JUnit 测试(正向和负向测试)

java - 我如何模拟 java.net.URL 或以编程方式设置 spring bean 来接受构造函数参数?

c# - 需要 OAuth token 的单元测试 API

java - void 方法应使用哪个测试替身

java - 如何在 SpringJUnit4ClassRunner 中模拟缺少的 bean 定义?

android - 在 Cordova 中,如何为 ios 和 android 指定不同的包名称?

java - ProgressDialog 未启动 - Android (java)

android - 在 ListView 上方添加图像