java – 在Robolectric测试中使用Android KeyStore
作者:互联网
我正在尝试编写一些与Android Keystore相反的测试用例.但是,当我编写以下测试用例时:
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class FancyPantsUnitTest {
@Test
public void buildKey() {
keyPairGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
keyPairGenerator.initialize(4096);
final KeyPair keyPair = keyPairGenerator.generateKeyPair();
}
}
这失败,出现以下异常:
org.junit.ComparisonFailure: expected:<null> but was:<java.security.KeyStoreException: AndroidKeyStore not found>
如果有帮助,我的目标是API等级23.
最佳答案:
目前已在https://github.com/robolectric/robolectric/issues/1518讨论过这个问题.
简而言之:
From java.security.Security javadoc:
The default values of security properties are read from an
implementation-specific location, which is typically the properties
file lib/security/java.security in the Java installation directory.
…我们可能不想鼓励人们跟你一起玩.
看起来这需要一个方法拦截规则……尝试使用PowerMockito时会发生同样的情况.
标签:java,android,robolectric,android-keystore 来源: https://codeday.me/bug/20190516/1115289.html