&引用;RobolectrictTestRunner.class“;在Android Studio中无法识别
我正在尝试使用Robolectric运行单元测试,但Android Studio无法识别上的类:&引用;RobolectrictTestRunner.class“;在Android Studio中无法识别,android,unit-testing,android-gradle-plugin,robolectric,robolectric-gradle-plugin,Android,Unit Testing,Android Gradle Plugin,Robolectric,Robolectric Gradle Plugin,我正在尝试使用Robolectric运行单元测试,但Android Studio无法识别上的类: @RunWith(RobolectricTestRunner.class) 详情: classpath 'com.android.tools.build:gradle:3.0.0' 我正在导入依赖项: testImplementation "org.robolectric:robolectric:3.5.1" 以及: 它只是不显示导入类的选项。 我应该添加更多我忘记的依赖项吗 错误: err
@RunWith(RobolectricTestRunner.class)
详情:
classpath 'com.android.tools.build:gradle:3.0.0'
我正在导入依赖项:
testImplementation "org.robolectric:robolectric:3.5.1"
以及:
它只是不显示导入类的选项。
我应该添加更多我忘记的依赖项吗
错误:
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
RobolectricGradeleteStrunner
自Robolectric的第3版以来已被弃用。只需使用@RunWith(RobolectrictTestRunner.class)
看看official。我解决了这个问题,只是将测试类放在
src\test
文件夹中,而不是放在src\androidTest文件夹中,通常会有两种测试“androidTest”和“test”
如果添加依赖项,如androidTestImplementation'org.roblectric:roblectric:4.3.1'
,则robolectric包将仅在“androidTest”类中导入
如果添加依赖项,如testImplementation'org.roblectric:roblectric:4.3.1'
,则它们只能在“test”类中导入。我没有任何运气地遵循了大多数建议。
然后我将一个点(.)改为双冒号(:)
是
@RunWith(RobolectricTestRunner.class)
改为
@RunWith(RobolectricTestRunner::class)
我遵循官方文件,但错误仍然存在。。。还有其他建议吗?还有一些依赖性,我不知道…你能尝试用testImplementation代替testCompile吗。现在用gradle版本就不受欢迎了4@FakherandroidTestImplementation和testImplementation不识别的错误相同。我使用:androidTestImplementation'com.android.support.test:runner:1.0.1',它在同一个项目上正常工作,只是Robolectric不工作。Robolectric总是test
而不是androidTest
dependencydude。。。你保存life@JacktheRipper哈哈,很高兴能帮上忙!!很不错的。谢谢。但为什么会这样呢?有没有办法将其配置为接受src\androidTest?很好!!这很有帮助!!我花了1个小时来解决这个问题,直到找到你的答案,谢谢。我刚刚添加了androidTestImplementation和testImplementation
@RunWith(RobolectricTestRunner::class)