Android studio says "Empty Test Suite" for AndroidTestCase
Solution 1
Since nobody else mentions it: methods in AndroidTestCase
subclasses need to be public
and have names starting with "test"!
The OP and the answers all got this right but I missed it and got the exact same error.
Solution 2
I got this error when running tests from Android Studio. Turned out I had placed my test cases in the wrong folder. When running Gradle/Android Studio, all Android tests should be in the folder src/instrumentTest/java
.
Edit: In Gradle plugin version 0.9 or later the correct name of the folder is androidTest
. (http://tools.android.com/tech-docs/new-build-system/migrating_to_09)
Solution 3
I understand that this question is old, and the development tools have changed significantly since this question has been asked.
However, I had a similar issue (in AndroidStudio 2.1.1) and it turned out that it was just the error message that was quite misleading. For me it said:
Test running started
Test running failed: Instrumentation run failed due to 'java.lang.IllegalStateException'
Empty test suite.
(Note: The difference to the original question is in IllegalStateException vs. RuntimeException)
It turned out that this IllegalStateException
was actually thrown in the initialization of the application context as can be seen by inspecting the logcat output. As a result, no test-methods were run, and Android Studio writes this somewhat misleading "Empty test suite" error.
I.e. "Empty test suite" can mean what it actually says (you don't have any test methods declared, e.g. because you forgot to annotate them with @Test
), but it can also mean that something (like a runtime exception thrown in your application initialization code) prevents the test-runner from reaching any test methods (which seems to be your case).
Check adb-logcat and search for RuntimeException
s. This will probably find you the root-cause of your problem.
Solution 4
I got this error because one of my test methods didn't include "throws exception" after the method signature. might help somebody
Solution 5
I got the same issue. I was having testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
in my defaultConfig {...}
. I have just removed that line, and now it's working fine (The IDE is picking the right runner config on build time).
I hope this will help someone.
Pratik Mandrekar
Updated on January 11, 2020Comments
-
Pratik Mandrekar over 4 years
I have created an example test case that extends AndroidTestCase. When I run the test case, it errors out by saying
Running tests Test running startedTest running failed: Instrumentation run failed due to 'java.lang.RuntimeException' Empty test suite.
The test case
import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import static org.junit.Assert.assertEquals; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import java.lang.Exception; import java.lang.Override; public class DateFormatTest extends AndroidTestCase{ @Override protected void setUp() throws Exception { super.setUp(); } @Override protected void tearDown() throws Exception { super.tearDown(); } public DateFormatTest(){ super(DateFormatTest.class); } @SmallTest public void testMultiply() { assertEquals("10 x 5 must be 50", 50, 10*5); } }
-
Pratik Mandrekar over 10 yearsI already have a default constructor in my test case.
-
IgorGanapolsky about 10 yearsWhere is it specified that this is the mandatory file structure for Android tests?
-
IgorGanapolsky about 10 yearsYeah, I already have default constructors as well, and this error keeps happening.
-
emidander about 10 yearsIt's not actually mandatory, it's just the default folder structure. You can read more about it on the Android tools site: tools.android.com/tech-docs/new-build-system. When I wrote the answer above I could not get tests to work outside the default structure, but the Gradle Android build system is a work in progress so the problem might be gone by now.
-
bsautner about 10 yearsper emidander's link above, a breaking change in the build system was put in so the new folder structure should be: src/androidTest/java
-
stevebot over 9 yearsthis - anyone running into this issue today, its likely because you upgraded gradle and still have your folder named instrumentTest and not androidTest
-
Monica about 8 yearsI think I tried everything mentioned in the answers to this question. Still I get the output: "Running tests Test running startedFinish Empty test suite." with no error. I asked a question at stackoverflow.com/questions/35426990/…
-
Pau Arlandis Martinez over 7 yearsThe same error of the question still happens even after trying this solution. Is not enough extends from AndroidTestCase.
-
i_me_mine over 7 yearsmethods must have names starting with "test", got me :)
-
IcedDante almost 7 yearsThis was my source of error. I was actually throwing a few specific exceptions, just not the generic "Exception". Why this would be a requirement is beyond me since I didn't see it in the docs.
-
bartonstanley almost 7 yearsBy definition the "default constructor" is a constructor with no arguments.
-
VonSchnauzer over 6 yearsYup - this got me to. Nice tip!