Type Android Junit4 not present exception

后端 未结 6 499
陌清茗
陌清茗 2021-01-01 08:41

I have an Android project that I am trying to run Instrumentation tests for using AndroidStudio, but when I try to run the whole class file for the tests, I get the exceptio

相关标签:
6条回答
  • 2021-01-01 09:00

    I had the same with:

    Type androidx.test.ext.junit.runners.AndroidJUnit4 not present
    

    I tried a lot of things before manually removing the App from the device and running the test again. Hope this helps!

    0 讨论(0)
  • 2021-01-01 09:07

    For me this actually seemed to be caused by an internet connection issue. Turning off and on wifi fixed and rebuilding seemed to fix.

    0 讨论(0)
  • 2021-01-01 09:12

    Writing steps if someone facing issue while edit configuration for above @Bohsen's answer

    1. In Android Studio, click Run > Edit Configurations (or press alt + shift + f10 if on Windows) to open the configuration editor.
    2. The left panel of the window shows configurations and their groups.
      • Android JUnit group
      • Android instrumented tests

    If your test is an instrumentation test, delete it from any JUnit tests groups.

    If your test is a JUnit test, delete it from any instrumentation test groups.

    For example, my test (DBTest.kt) was appearing in both Android JUnit and Instrumented group's section. So I deleted from JUnit group and ran it again, it was working fine.

    0 讨论(0)
  • 2021-01-01 09:18

    I got this issue when I did my tests on the emulator.

    I fixed it by downloading a new project copy from the git repository.

    0 讨论(0)
  • 2021-01-01 09:20

    Hopefully someone can give you a better answer as to why, but I had this exact same problem. I did the following:

    • Build > Clean Project,
    • Ran the app on the emulator

    This done, I was able to get back into a state where I could run the tests again.

    0 讨论(0)
  • 2021-01-01 09:21

    This is caused by Android Studio trying to execute an instrumentation test as a JUnit test.

    I had to go to 'Edit Configurations...' and delete the configuration from Android JUnit group and manually add to the 'Android Instrumented Tests' group. After this I had no problem executing the tests.

    In Android Studio, click Run > Edit Configurations.

    https://developer.android.com/studio/run/rundebugconfig

    0 讨论(0)
提交回复
热议问题