Why can't I import AndroidJUnit4 and ActivityTestRule into my unit test class?

后端 未结 8 560
一个人的身影
一个人的身影 2020-12-08 02:02

I\'m having trouble importing some of the Android UI testing framework classes - I just can\'t figure out what is going wrong!

This is my class:

@Run         


        
8条回答
  •  無奈伤痛
    2020-12-08 02:24

    For writing UI tests((tests that run on Android Device/Emulator)) in Android, make sure that

    1. The Test classes are in androidTest package rather that test package.

    2. Make sure you make the following dependencies in build.gradle

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    testImplementation 'junit:junit:4.13'
    

    For Unit Testing(tests that run on JVM) make sure

    1.Test classes are in test package

    2.Make sure you make the following dependencies in build.gradle

    testImplementation 'junit:junit:4.13'
    testImplementation 'org.mockito:mockito-core:2.23.0'
    

提交回复
热议问题