0

i have .apk file and i want to test it using robotiun and i have followed the procedure but when i run the app using junit test i am getting an error as Test run failed: Instrumentation run failed due to 'Process crashed.'

This is my androidmanifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.metago.astro.test" android:versionCode="1" android:versionName="1.0">

    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />>

    <instrumentation android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.metago.astro" />

    <application android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <uses-library android:name="android.test.runner" />     
    </application>

</manifest>

My TestActivity.java file is

        @SuppressWarnings("unchecked")
    public class TestActivity extends ActivityInstrumentationTestCase2 {    
        private static final String TARGET_PACKAGE_ID = "com.metago.astro";
        private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.metago.astro.SplashActivity";    
        private static Class<?> launcherActivityClass;
        static {
            try {
                launcherActivityClass = Class
                        .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }    
        public TestActivity() throws ClassNotFoundException { 
            super(TARGET_PACKAGE_ID, Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME)); 
            }

        private Solo solo;

        @Override
        protected void setUp() throws Exception {
            solo = new Solo(getInstrumentation(), getActivity());
        }    
        public void testCanOpenSettings() {
            solo.pressMenuItem(0);
        }    
        @Override
        public void tearDown() throws Exception {
            solo.finishOpenedActivities();
        }
    }

My logcat is

        FATAL EXCEPTION: main
        java.lang.ExceptionInInitializerError
        at java.lang.Class.newInstanceImpl(Native Method)
        at java.lang.Class.newInstance(Class.java:1319)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4424)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.metago.astro.SplashActivity
        at com.metago.astro.TestActivity.<clinit>(TestActivity.java:19)
        ... 15 more
         Caused by: java.lang.ClassNotFoundException: com.metago.astro.SplashActivity
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:217)
        at java.lang.Class.forName(Class.java:172)
        at com.metago.astro.TestActivity.<clinit>(TestActivity.java:17)
        ... 15 more
        Caused by: java.lang.NoClassDefFoundError: com/metago/astro/SplashActivity
        Caused by: java.lang.ClassNotFoundException: com.metago.astro.SplashActivity
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        ... 19 more

Line no 17 is .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);

Abhinai
  • 1,082
  • 2
  • 13
  • 20

1 Answers1

1

The package name for your test project needs to be different from the package name for the application you want to test. The package name must be a unique identifier. In your test application you should use something like package="com.metago.astro.test"

Also, you may need to add the following permission:

<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • it is saying that Test run failed: Unable to find instrumentation target package: com.metago.astro.test – Abhinai Aug 06 '12 at 11:16
  • No. Set `targetPackage="com.metago.astro"` but set `package="com.metago.astro.test"` in the first line of the manifest for the test project. – David Wasser Aug 06 '12 at 11:18
  • thanks sir, but i am getting another error as Test run failed: Instrumentation run failed due to 'Process crashed.' – Abhinai Aug 06 '12 at 11:25
  • What's in the logcat this time? – David Wasser Aug 06 '12 at 13:26
  • i dont know what is happening but i changed my targetPackage="com.metago.astro" i am getting the same error as Test run failed: Unable to find instrumentation target package: com.metago.astro and there are no errors in the logcat – Abhinai Aug 07 '12 at 06:32
  • You could try getting rid of the static initializer and making your constructor look like this: `public TestActivity() throws ClassNotFoundException { super(TARGET_PACKAGE_ID, Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME)); }` – David Wasser Aug 07 '12 at 16:49
  • i am getting the same error when i changed the TestAvtivity() error is Test run failed: Unable to find instrumentation target package: com.metago.astro – Abhinai Aug 08 '12 at 06:24
  • 3
    Post the manifest for both your test project and your target project. If you are using Eclipse please close Eclipse, restart it, clean your project, rebuild your project from scratch and wave a dead chicken over your head while praying to the God (or Gods) of your choice). – David Wasser Aug 08 '12 at 07:23
  • i a running this test application through .apk file i unsigned it and got the package name and followed the link http://code.google.com/p/robotium/wiki/RobotiumForAPKFiles – Abhinai Aug 08 '12 at 08:01
  • Well, did you resign the APK and does it successfully install on the phone? Are you sure that you've typed the package name correctly? – David Wasser Aug 08 '12 at 09:28
  • i have resigned the app and it is working on the emulator and the package name is com.metago.astro – Abhinai Aug 08 '12 at 09:38
  • Sorry, I have no other ideas. – David Wasser Aug 08 '12 at 10:16