gpt4 book ai didi

java - Robolectric 给出 java.security.KeyStoreException : AndroidKeyStore not found

转载 作者:搜寻专家 更新时间:2023-11-01 09:33:12 24 4
gpt4 key购买 nike

所以我编写了我的应用程序,其中我使用 KeyStore 来加密/解密数据。我还为它编写了一个很好的 Robolectric 测试,但是当我尝试运行测试时,出现以下异常:

java.security.KeyStoreException: AndroidKeyStore not found

对于以下代码:

keyStoreInstance = KeyStore.getInstance("AndroidKeyStore");

有什么解决办法吗?

我只找到了这个: https://github.com/robolectric/robolectric/issues/1518

最佳答案

所以,这背后的原因是当您通过 Robolectric 运行时,AndroidKeyStore 实现不存在。 Using the Android KeyStore in Robolectric tests

您可以使用以下方法避免此异常:

isTestRunner(){
return Build.FINGERPRINT.equalsIgnoreCase("robolectric");
}

如果你有一个类让 YourKeystore.class 注入(inject)到许多其他类中,你仍然可以模拟你的 YourKeystore.class,这使你能够测试其他类。如果您想测试 YourKeystore.class 本身,恐怕这是不可能的(请参阅上面的链接)。

关于java - Robolectric 给出 java.security.KeyStoreException : AndroidKeyStore not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45491441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com