Class not found: Empty test suite when running unit tests in Android Studio
AndroidUnit TestingAndroid Problem Overview
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
Android Solutions
Solution 1 - Android
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 - Android
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 - Android
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'
Solution 4 - Android
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.
Solution 5 - Android
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
Solution 6 - Android
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
}
}
}
Solution 7 - Android
If you use Robolectric you may need to set Working directory in run configuration as $MODULE_DIR$
Also set VM Options : -ea or: -noverify
Solution 8 - Android
In my case this was cause by an exception being thrown in the @BeforeClass method.
Solution 9 - Android
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!
Solution 10 - Android
Work for me:
- Build > Clean Project
- Run test
Solution 11 - Android
For me finally worked:
- ./gradlew check - checked all the errors and tried to fix as many of them.
- Restarted Android Studio
- Created a new configuration for Android JUnit, test kind: all in the directory, selected test directory (app/src/test) and app module.
- Run tests
Solution 12 - Android
I had the same issue. I created Suite Class and it resolved the issue
Solution 13 - Android
Solved it using a lower gradle version
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
That will have to do for now