androidx.test.InstrumentationRegistry is deprecated

后端 未结 6 897
耶瑟儿~
耶瑟儿~ 2020-12-24 04:49

Switched to AndroidX and received deprecated: import androidx.test.InstrumentationRegistry.

If I made next import: import androidx.te

6条回答
  •  抹茶落季
    2020-12-24 05:45

    When you're using Android X you need to make sure you have the following in your app's build.gradle file

    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    

    The second one is to make sure you have the correct AndroidJUnit4 to use in your tests.

    Make sure you import both of these.

    import androidx.test.platform.app.InstrumentationRegistry
    import androidx.test.ext.junit.runners.AndroidJUnit4
    

    Now instead of using val context = InstrumentationRegistry.getContext() you can use the line shown below

    val context = InstrumentationRegistry.getInstrumentation().getTargetContext()
    

提交回复
热议问题