androidx.test.InstrumentationRegistry已弃用 [英] androidx.test.InstrumentationRegistry is deprecated

查看:1496
本文介绍了androidx.test.InstrumentationRegistry已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

切换到AndroidX并已弃用:import androidx.test.InstrumentationRegistry.

如果我进行下一次导入:import androidx.test.platform.app.InstrumentationRegistry 我不能使用getContext().

If I made next import: import androidx.test.platform.app.InstrumentationRegistry I can't use getContext().

例如: val context = InstrumentationRegistry.getContext().

build.gradle中:

androidTestImplementation 'androidx.test.ext:junit:1.0.0-beta02'
androidTestImplementation 'androidx.test:runner:1.1.0-beta02'

推荐答案

在大多数情况下,您可以从

You can use InstrumentationRegistry.getInstrumentation().getTargetContext() in the most cases from androidx.test.platform.app.InstrumentationRegistry.

如果需要该应用程序,则可以使用ApplicationProvider.getApplicationContext<MyAppClass>().

If you need the Application, you can use ApplicationProvider.getApplicationContext<MyAppClass>().

如果您还没有,我想您也可以使用新的测试依赖项: androidTestImplementation 'androidx.test:core:1.0.0-beta02'.

If you haven't already, I think you can also use the new test dependency: androidTestImplementation 'androidx.test:core:1.0.0-beta02'.

这篇关于androidx.test.InstrumentationRegistry已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆