0

.apk ファイルがあり、robotiun を使用してテストしたいのですが、手順に従いましたが、junit テストを使用してアプリを実行すると、「テストの実行に失敗しました: インストルメンテーションの実行に失敗しました」というエラーが表示されます。

これは私の 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>

私の TestActivity.java ファイルは

        @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();
        }
    }

私のlogcatは

        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

17 行目は .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); です。

4

1 に答える 1

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" />
于 2012-08-06T11:12:52.000 に答える