I have some requirements where I should run the test project anytime on my device, without connecting it to system and running through eclipse.
I added some intent-filter
to my AndroidManifest.xml
to make the test project visible on the launcher, however, it never runs successfully and is not able to find the target activity class
Meanwhile, If I connect the device to system, and from eclipse perform Run As Android Junit
, it runs successfully without any exception. So what is wrong here? Am i missing some concept ?
Below is the AndroidManifest.xml
of my test application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.org.search.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="18"/>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.third.party.packageName" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
<activity android:name="com.org.search.test.MyTestClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is the exception log
java.lang.ExceptionInInitializerError
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException:
com.third.party.packageName.SearchActivity
at com.expedia.search.test.ExpediaHotelsScraper.<clinit>(ExpediaHotelsScraper.java:35)
... 15 more
Caused by: java.lang.ClassNotFoundException: com.third.party.packageName.SearchActivity
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at java.lang.Class.forName(Class.java:169)
at com.org.search.test.MyTestClass.<clinit>(MyTestClass.java:32)
... 15 more
Caused by: java.lang.NoClassDefFoundError: com/third/party/packageName/activity/SearchActivity
... 19 more
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.third.party.packageName.SearchActivity" on path:
DexPathList[[zip file "/system/framework/android.test.runner.jar",
zip file "/data/app/com.org.search.test-1.apk"],
nativeLibraryDirectories=[/data/app-lib/com.org.search.test-1,
/vendor/lib, /system/lib]]
Also the test class code MyTestClass.java
public class MyTestClass extends ActivityInstrumentationTestCase2 {
private static final String LAUNCH_ACTIVITY_NAME =
"com.third.party.packageName.activity.SearchActivity";
private Solo solo;
private static Class<?> splashActivityClass;
static {
try {
splashActivityClass = Class.forName(LAUNCH_ACTIVITY_NAME);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public MyTestClass() throws ClassNotFoundException {
super(splashActivityClass);
}
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testAllCountries() {
//my test goes here
}
I am new to android automation. Please help me understand the concept if am trying something infeasible.