切换到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'
发布于 2018-10-22 23:00:30
在大多数情况下,您可以在androidx.test.platform.app.InstrumentationRegistry
中使用InstrumentationRegistry.getInstrumentation().getTargetContext()
。
如果您需要该应用程序,您可以使用ApplicationProvider.getApplicationContext<MyAppClass>()
。
如果您还没有,我认为您还可以使用新的测试依赖项:androidTestImplementation 'androidx.test:core:1.0.0-beta02'
。
https://stackoverflow.com/questions/52924431
复制相似问题