Why is the Android test runner reporting "Empty test suite"?
I am banging my head against the wall here trying to figure out why IntelliJ/Android is reporting "Empty test suite". I have a small project with two IntelliJ Modules ("Projects" in Eclipse). The Unit test module has its own AndroidManifest.xml, which I have pasted at the bottom. I am trying to run an ActivityUnitTestCase
, since the tests will be dependent upon the Context
-object.
The package name of the main module is nilzor.myapp
. The pacakge name of the test module is nilzor.myapp.tests
Why is not the test runner detecting the testBlah()
-method as a test?
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nilzor.myapp.tests"
android:versionCode="1"
android:versionName="1.0">
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner"/>
</application>
<!--
This declares that this application uses the instrumentation test runner targeting
the package of nilzor.myapp. To run the tests use the command:
"adb shell am instrument -w nilzor.myapp.tests/android.test.InstrumentationTestRunner"
-->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="nilzor.myapp"
android:label="Tests for nilzor.myapp"/>
</manifest>
And here is my test class:;
package nilzor.myapp.tests;
public class NilzorSomeTest<T extends Activity> extends ActivityUnitTestCase<T>{
public NilzorSomeTest(Class<T> activityClass){
super(activityClass);
}
@SmallTest
public void testBlah(){
assertEquals(1,1);
}
}
I have read the testing fundamentals, the activity testing document, and tried following this Hello world test blog, even though it is for Eclipse. I cannot get the test runner to find and run my test. What am I doing wrong?
Some of the questions I still feel unsure about are:
- Do I need an Annotation above the Unit test method?
- Do I need to prefix the method with "test", or is that just for JUnit tests?
- Can I have tests in sub-packages of
nilzor.myapp.tests
?
But the main question of this post is why does not the test runner detect my test?
Solution 1:
You need to provide default constructor for your test class, for example:
package nilzor.myapp.tests;
public class NilzorSomeTest extends ActivityUnitTestCase<ActivityYouWantToTest>{
public NilzorSomeTest(){
super(ActivityYouWantToTest.class);
}
@SmallTest
public void testBlah(){
assertEquals(1,1);
}
}
about your other questions:
No. My tests still run without any annotations, but I guess it's a good practice to have them. It allows you to specify size of tests to run. See What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android? for more detail.
Yes, you need "test" prefix. InteliJ gives "method never used" warning when there's no "test" prefix, and skips that method during test run.
Yes. I have my tests organized into subpackages and it seems to be working well.
Solution 2:
If this is happening "all of a sudden" or "it was working 5 minutes ago" my solution was to go into Run/Debug configurations and remove any configurations under "Android Tests". Sometimes these configurations get corrupted if I refactor the class under test (for example by moving to an new package).