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:
nilzor.myapp.tests
?But the main question of this post is why does not the test runner detect my test?
The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This test runner supports several common testing tasks, including the following: Writing JUnit tests. Accessing the app's context. Filtering tests.
Yes You can delete them ,you can go to build. gradle and then remove following dependencies which comes preloaded in any new android project. and then click on the androidTest and Test package and Press Delete they will be removed !
The suite is built using the Android testing framework. The runner is implemented as a single instrumentation test that executes the test package and parses the result log. The logs are taken directly from the device (logcat).
Right click on a test class name in the editor (or a filename in the project explorer) to run all tests in a single class. The default keyboard shortcut for this is Ctrl+Shift+F10 on Linux.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With