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
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!
For me this actually seemed to be caused by an internet connection issue. Turning off and on wifi fixed and rebuilding seemed to fix.
Writing steps if someone facing issue while edit configuration for above @Bohsen's answer
Run > Edit Configurations
(or press alt + shift + f10
if on Windows) to open the configuration editor.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.
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.
Hopefully someone can give you a better answer as to why, but I had this exact same problem. I did the following:
This done, I was able to get back into a state where I could run the tests again.
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