I'm getting errors when I'm trying to run insturmentation tests on android. I've written an Activity, called AudioPlayerActivity that lies in the package com.mycompany.mobile.android.gui, and now I'm trying to test the GUI of that project and I'm running in the following error:
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.mycompany.mobile.android.gui/.AudioPlayerActivity }
I have read this question, and followed the advice there, but to no avail. I also googled for the error, but did not find any help.
This is how my AndroidManifest.xml for the test project looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.mobile.android.gui"
android:versionCode="1"
android:versionName="1.0" >
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.mycompany.mobile.android.gui" />
<application>
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:targetSdkVersion="7" />
<supports-screens android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
And here's my Instrumentation test.
package com.mycompany.mobile.android.gui;
import android.test.ActivityInstrumentationTestCase2;
import com.mycompany.mobile.android.gui.AudioPlayerActivity;
public class TestMusicPlayerActivityTest extends ActivityInstrumentationTestCase2<AudioPlayerActivity> {
public TestMusicPlayerActivityTest() {
super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class);
}
public TestMusicPlayerActivityTest(String name) {
super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class);
}
public TestMusicPlayerActivityTest(String pkg, Class<AudioPlayerActivity> activityClass) {
super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class);
}
public void testSomething() {
System.out.println("Nothing works :(");
System.out.println(getActivity());
}
}
We are running the entire process via maven, but that should not be a part of the problem.
The tested Activity, as you can see, also lies in the same package. I don't call the super constructor with the activity's instead of the package name, as most people having this issue do.
For your interest, this is the AndroidManifest.xml describing the tested activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.mobile.android.gui"
android:versionCode="1"
android:versionName="1.0" >
<!-- omitted Uses permission + Uses SDK -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:debuggable="true"
android:theme="@style/NoTitleBar"
>
<!-- omitted other activities -->
<activity
android:name="com.mycompany.mobile.android.gui.AudioPlayerActivity"
android:screenOrientation="portrait" ></activity>
</application>
</manifest>
I also added the activity to the AndroidManifest.xml, but this didn't change anything. I also tried adding the MAIN/LAUNCHER intent filter for the desired activity, but to this didn't change the outcome of the test. I have tried starting the activity with extras and without them, that also didn't change the outcome.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.mobile.android.gui"
... ...
Are you using the same package name for both your Android project and Android test project? This could be a problem, though I am not sure if it causes your java.lang.RuntimeException.
According to the official dev guide here, Your test project must have a different package name from you tested project:
An Android package name is a unique system name for a .apk file, set by the "android:package" attribute of the element in the package's manifest. The Android package name of your test package must be different from the Android package name of the application under test. By default, Android tools create the test package name by appending ".test" to the package name of the application under test.
Try using package name com.mycompany.mobile.android.gui.test for your test project.