android - Robolectric does not support API level 28
问题描述
Although this question has been answered for previous versions in other threads, none of the answers seems to work for me with api 28 right now so..
All Robolectric tests worked fine when on api 27. Now when my app api target is 28 they all fail.
I have
@Config(constants = BuildConfig::class, sdk = [Build.VERSION_CODES.P])
on my test class.
Diving into Robolectrics internal SdkConfig.java it looks like they add support for api 28:
addSdk(Build.VERSION_CODES.P, "P", "4651975", "P");
But when evaluating that line of code in the debugger, Build.VERSION_CODES.P
evaluates to 10000
. Not sure what's going on there.
I'm running Robolectric 3.8, and also tried with the 4.0 alpha version with no luck.
What am I missing?
Edit: For now I'm just running on the latest (what I can tell) supported api version, by annotating the test class(es) with @Config(sdk = [Build.VERSION_CODES.O_MR1])
. This will give you Android 8.1.0 (api 27).
解决方案
要完成 Algar 的答案,您可以通过像这样注释您的测试类来暂时绕过此错误(同时 Robolectric 修复此问题):
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O_MR1])
class YourUnitTests {
...
}
它将强制 Robolectric 使用 Android API 27。
推荐阅读
- java - 如何在循环中模拟具有迭代的服务方法?
- java - Java中的运行长度编码 - 意外输出
- php - php - 如何通过 id 获取 xml 标签
- azure - 手动更改配置文件后,Ambari 是否恢复配置?
- ios - Google 放置 iOS sdk,按 lat,long 位置获取位置
- angular - Msal Angular Preview Azure AD 同意范围和访问令牌版本错误
- ios - 使用自定义动画呈现嵌入在导航控制器中的视图控制器
- redmine - Redmine、SMTP 和 Mandrill 自定义标题模板
- django - Django 1.11 多对多
- spring - 创建名称为“customerController”的 bean 时出错:通过字段“customerDAO”表示的依赖关系不满足;