ActivityInstrumentationTestCase2を拡張するテストクラスを実行したいと思います。しかし、私は次のログを取得しました。Oncreateでターゲットアクティビティにブレークポイントを設定しましたが、そこに到達しなかったため、エラーが発生しました。
[2012-07-30 18:14:42 - myapp] Uploading myapp.apk onto device '66313d1c'
[2012-07-30 18:14:47 - myapp] Installing myapp.apk...
[2012-07-30 18:14:57 - myapp] Success!
[2012-07-30 18:14:57 - mytestapp] Launching instrumentation android.test.InstrumentationTestRunner on device 66313d1c
[2012-07-30 18:14:57 - mytestapp] Collecting test information
[2012-07-30 18:14:58 - mytestapp] Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'
これは私がしました:
adb shell pm list instrumentation
テストアプリが表示されました。
ログ全体:
07-30 20:37:16.172: W/dalvikvm(19499): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
07-30 20:37:16.202: E/AndroidRuntime(19499): FATAL EXCEPTION: main
07-30 20:37:16.202: E/AndroidRuntime(19499): java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{mytestapp/android.test.InstrumentationTestRunner}: java.lang.RuntimeException: Could not instantiate test class. Class:myapp.activity.myactivityTest
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3257)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.app.ActivityThread.access$2200(ActivityThread.java:117)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.os.Looper.loop(Looper.java:130)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.app.ActivityThread.main(ActivityThread.java:3691)
07-30 20:37:16.202: E/AndroidRuntime(19499): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 20:37:16.202: E/AndroidRuntime(19499): at java.lang.reflect.Method.invoke(Method.java:507)
07-30 20:37:16.202: E/AndroidRuntime(19499): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
07-30 20:37:16.202: E/AndroidRuntime(19499): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
07-30 20:37:16.202: E/AndroidRuntime(19499): at dalvik.system.NativeStart.main(Native Method)
07-30 20:37:16.202: E/AndroidRuntime(19499): Caused by: java.lang.RuntimeException: Could not instantiate test class. Class:myapp.activity.myactivityTest
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.AndroidTestRunner.runFailed(AndroidTestRunner.java:233)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.AndroidTestRunner.buildSingleTestMethod(AndroidTestRunner.java:100)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:51)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:81)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:418)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:399)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:364)
07-30 20:37:16.202: E/AndroidRuntime(19499): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3254)
myactivityTestactivity
package myapp;
import myapp.R;
import android.test.ActivityInstrumentationTestCase2;
public class myactivityTest extends ActivityInstrumentationTestCase2<myactivity> {
public ImportFileSelectorTest(String name) {
super("myactivity", myactivity.class);
}
protected final void setUp() throws Exception {
super.setUp();
}
protected final void tearDown() throws Exception {
super.tearDown();
}
public void testSimpleDefaults(){
assertTrue(true);
}
}
ヒントは役に立ちます。ありがとうございました。