AndroidJUnit4.class is deprecated: How to use androidx.test.ext.junit.runners.AndroidJUnit4?

前端 未结 8 1649
傲寒
傲寒 2020-12-04 08:04

For my instrumentation tests I was using

@RunWith(AndroidJUnit4.class)

from

import androidx.test.runner.AndroidJUnit4;
         


        
8条回答
  •  抹茶落季
    2020-12-04 08:53

    1. Include these lines in build.gradle app module.

      testImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'

    2. In the test class replace your test runner to

      import androidx.test.ext.junit.runners.AndroidJUnit4;

    3. If InstrumentationRegistry.getTargetContext() is deprecated use InstrumentationRegistry from androidx.test.platform.app like this

      InstrumentationRegistry.getInstrumentation().getTargetContext()

提交回复
热议问题