64

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

3
  • If you are using Robolectric, check if the test file is in the $MODULE$/test directory instead of $MODULE$/androidTest It happened to me, I spent about one hour to figured it out
    – crgarridos
    Jun 25, 2018 at 3:00
  • 1
  • I have a similar problem but it only happens once after opening Android studio. But all I have to do is try to run the test a second time. Then it runs and continues to run until I have to restart Android studio. Something is not right but the annoyance has been little enough that I have ignored it to date. Dec 13, 2018 at 12:19

13 Answers 13

85

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.

4
  • 3
    The cause in my case was that I had switched to a release build config at some point which has a different applicationId. Android Studio kept trying to use the release applicationId for the test even though I switched back to the debug config. Sep 19, 2017 at 23:55
  • 1
    When this happens I just delete all my run configs from AS, as described above, and try again. Likely it's happened because I made some changes to the test class or switched to a branch where there are differences in the test class. Jan 10, 2019 at 3:39
  • 1
    Thanks ! I spent a lot of time to understand what was happening.I also had an issue between release and debug.
    – Laurent D.
    Jun 20, 2019 at 7:52
  • 1
    Tha'nks this was exactly my problem Feb 16, 2020 at 21:54
24

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
1
  • 2
    Thank you, this worked, seems like Android Studio bug. I also had to remove my tests from Unit Tests section, it was mistakenly registered there for obscure reasons.
    – Kurovsky
    Oct 10, 2019 at 10:42
16

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'
0
15

I had the same problem. I noticed that the method under test was being displayed in the Run/Debug configuration drop-down as:
TestClassName.testMethod()
rather than the correct:
testMethod()

I fixed it by deleting the TestClass.testMethod() Run/Debug configuration for the test method which was giving this error, then re-running the test.

If that recreates the same problem, delete the incorrect Run/Debug configuration, then right-click on the test method and select:
Create 'testMethod()'...
(rather than Run or Debug) to create a working configuration.

1
  • 1
    Crap! Two years later and this hack still helps.
    – Giszmo
    Sep 26, 2018 at 4:10
5

I had this problem, and none of the answers on this post (or the other highly-visible Stack Overflow posts) resolved it for me.
However, manually running the gradle task compileTestKotlin appears to have resolved the issue for me.

This was for Kotlin tests, Android Studio 3.1.2

0
3

If you are working on a team, check all your build.gradle files to make sure nobody is disabling the test tasks. I had the 'empty test suite' error and eventually found it was caused by the following in build.gradle at the project root:

gradle.taskGraph.whenReady {
    tasks.each { task ->
        if (task.name.contains("Test"))
        {
            task.enabled = false
        }
    }
}
2

If you use Robolectric you may need to set Working directory in run configuration as $MODULE_DIR$enter image description here

Also set VM Options : -ea or: -noverify

http://robolectric.org/getting-started/

0

In my case this was cause by an exception being thrown in the @BeforeClass method.

0

Happened to me in AS 3.3.

I'm using flavors and this happened in a module which only has src/main and src/test. The app module has src/main src/common and src/flavor. The build type selected in AS was flavorDebug.

To fix it I went to "Run Configurations" and in the "Use classpath of module" dropdown the app module was selected. Select the module that you would like to test and voila!

0

Work for me:

  • Build > Clean Project
  • Run test
0

For me finally worked:

  1. ./gradlew check - checked all the errors and tried to fix as many of them.
  2. Restarted Android Studio
  3. Created a new configuration for Android JUnit, test kind: all in the directory, selected test directory (app/src/test) and app module.
  4. Run tests
-3

I had the same issue. I created Suite Class and it resolved the issue

-4

Solved it using a lower gradle version

dependencies {
    classpath 'com.android.tools.build:gradle:2.0.0'

That will have to do for now

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.