Type Android Junit4 not present exception
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.
Writing steps if someone facing issue while edit configuration for above @Bohsen's answer
- In Android Studio, click
Run > Edit Configurations
(or pressalt + shift + f10
if on Windows) to open the configuration editor. - 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.
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