【发布时间】:2017-11-14 11:24:25
【问题描述】:
我正在尝试使用 Robolectric 运行单元测试,但 Android Studio 无法识别以下类别:
@RunWith(RobolectricTestRunner.class)
详情:
classpath 'com.android.tools.build:gradle:3.0.0'
我正在导入依赖项:
testImplementation "org.robolectric:robolectric:3.5.1"
还有:
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
它根本没有出现导入类的选项。 我应该添加更多我忘记的依赖项吗?
错误:
error: package org.robolectric does not exist
error: package org.robolectric does not exist
error: package org.robolectric.shadows does not exist
error: cannot find symbol class RobolectricTestRunner
error: cannot find symbol variable Robolectric
error: cannot find symbol variable ShadowApplication
【问题讨论】:
-
您可以尝试使用 testImplementation 而不是 testCompile。现在使用 gradle 版本 4 已弃用
-
@Fakher 错误与 androidTestImplementation 相同,但无法通过 testImplementation 识别。我使用: androidTestImplementation 'com.android.support.test:runner:1.0.1' 并且它在同一个项目上正常工作,只是不工作的机器人。
-
Robolectric 始终是
test而不是androidTest依赖项
标签: android unit-testing android-gradle-plugin robolectric robolectric-gradle-plugin