Class not found: Empty test suite when running unit tests in Android Studio

I have a test suite for my Android app, and all unit tests run fine. However, whenever I make a single change in one of my unit test classes (for example, ModelUnitTests), when trying to run that class again, I get this message

Process finished with exit code 1
Class not found: "xxx.xxxxxx.xxx.ModelUnitTests"Empty test suite.

If I do a gradle clean and then run the class tests again, it runs fine (but it takes 4 minutes to do...), but then a new change will break it again.

Any advice on how to fix this? I'm not exactly sure which test configuration should I post. I'm using the Unit Tests artifact and my tests are located on the module/src/test/package folder


Solution 1:

I had a similar problem and it was because I first created an Unit Test with the same class name. When I created the Instrumented Unit Test I got the error.

To solve it, I went to Edit Configurations, on the left of the run icon. Then below Unit Test, it was the 'conflicting' class, which I deleted. Click on Apply/Ok. Then I right click on the class name, click on run and voilà, it works.

Solution 2:

The fix on Android Studio is:

  • step 1.- Go to Run/Debug configuration
  • step 2.- Go to Android Tests section
  • step 3.- Remove the test configuration file with (-)
  • step 4.- Press Apply and OK
  • step 5.- Run the test again

Solution 3:

Just ran into this - writing my unit tests in Kotlin. In my case it turned out I forgot to add kotlin plugin in given modules build.gradle file:

apply plugin: 'kotlin-android'