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

前端 未结 8 1670
傲寒
傲寒 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:47

    If you've tried @MarcelGangwisch's solution and your build fails saying it can't find the resource AND you also cleaned/rebuilt your project and it still doesn't work, try this: (based also on @KrzysztofDziuba's solution)

    In your gradle file where you changed the dependency, make sure you are adding it as the type you need, ie.:

    For UI tests:

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

    For Unit tests:

    testImplementation 'androidx.test.ext:junit:1.1.0'

    In my instance I added it as both and now it works.

提交回复
热议问题