Cannot resolve symbol 'AndroidJUnit4'

前端 未结 19 2222
别跟我提以往
别跟我提以往 2020-12-02 08:48

Obviously I need the correct import statment to solve this problem. According to the docs for AndroidJUnit4, this should be

import android.support.test.runn         


        
19条回答
  •  攒了一身酷
    2020-12-02 09:31

    The common cause of this problem is that when adding below dependency:

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

    This is a correct dependency if you are going to use instrumented tests (tests in the androidTest java package)

    But for implementing local unit tests (tests in test java package) while using above mentioned dependency; then you'll face Cannot resolve symbol 'AndroidJUnit4'

    That is because androidTestImplementation directive is used to import libraries in instrumented tests, but not in the local JVM/unit tests.

    If you want to use AndroidJUnit4 in a local JVM/unit test, then use below dependency instead

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

    The same thing applies if you add the latter dependency while using AndroidJUnit4 in instrumented test, you will also get Cannot resolve symbol 'AndroidJUnit4'; because you're using the wrong directive.

提交回复
热议问题