切换到AndroidX
并收到弃用的:import androidx.test.InstrumentationRegistry
。
如果我做了下一个导入:import androidx.test.platform.app.InstrumentationRegistry
,我就不能使用getContext()
了。
例如:val context = InstrumentationRegistry.getContext()
。
在build.gradle
中
androidTestImplementation 'androidx.test.ext:junit:1.0.0-beta02'
androidTestImplementation 'androidx.test:runner:1.1.0-beta02'
发布于 2019-10-11 19:49:53
我花了很多时间在应用程序build.gradle
中使用testImplementation
而不是androidTestImplementation
和reverse来移动依赖项。
我的错误是我在test
文件夹而不是androidTest
文件夹中创建了测试类,因此得到了AndroidJuit4
和InstrumentationRegistry
的未解决的错误。
当我将我的测试文件转移到androidTest
文件夹中,然后在build.gradle
中使用androidTestImplementation
独立实现测试库的问题得到了解决。
https://stackoverflow.com/questions/52924431
复制相似问题