I had another problem using the InstrumentationTestRunner subclass.
Here's the code for the subclass:
package com.jlptquiz.app.tests; import junit.framework.TestSuite; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; public class MyInstrumentationTestRunner extends InstrumentationTestRunner { public TestSuite getAllTests(){ InstrumentationTestSuite suite = new InstrumentationTestSuite(this); suite.addTestSuite(UtilsTestCase.class); return suite; } public ClassLoader getLoader() { return MyInstrumentationTestRunner.class.getClassLoader(); } }
Here's the unit test:
package com.jlptquiz.app.tests; import com.jlptquiz.app.Utils; import junit.framework.Assert; import android.app.Activity; import android.content.Context; import android.net.wifi.WifiManager; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; public class UtilsTestCase extends ActivityInstrumentationTestCase2 { private Context mContext; private Utils utils; public static String TAG = "GetResourceStringTestCase"; public UtilsTestCase() { super("com.jlptquiz.app", Utils.class); } public void setup() { try { super.setUp(); } catch (Exception e) {
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jlptquiz.app" android:versionCode="1" android:versionName="1.0"> <application android:name="AppState" android:debuggable="true" android:clearTaskOnLaunch="true" android:icon="@drawable/ic_icon" android:label="@string/app_name"> <activity android:name="JlptQuizStartActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="QuestionActivity"></activity> <activity android:name="AnswerActivity"></activity> <activity android:name="SettingsActivity"></activity> <uses-library android:name="android.test.runner" /> </application> <instrumentation android:label="AllTests" android:name="com.jlpt.quiz.app.tests.MyInstrumentationTestRunner" android:targetPackage="com.jlptquiz.app"/> <uses-sdk android:minSdkVersion="5" /> </manifest>
And the launch configuration, android junit testing configuration, points MyInstrumentationTestRunner as an implementation of TestRunner.
But I came up with a class exception not found in MyInstrumentationTestRunner, according to logcat:
/AndroidRuntime( 835): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<< D/AndroidRuntime( 835): CheckJNI is ON D/AndroidRuntime( 835): Calling main entry com.android.commands.am.Am I/ActivityManager( 61): Force stopping package com.jlptquiz.app uid=10034 I/ActivityManager( 61): Start proc com.jlptquiz.app for added application com.jlptquiz.app: pid=843 uid=10034 gids={} D/AndroidRuntime( 843): Shutting down VM W/dalvikvm( 843): threadid=1: thread exiting with uncaught exception (group=0x40015560) E/AndroidRuntime( 843): FATAL EXCEPTION: main E/AndroidRuntime( 843): java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.jlptquiz.app/com.jlpt.quiz.app.tests.MyInstrumentationTestRunner}: java.lang.ClassNotFoundException: com.jlpt.quiz.app.tests.MyInstrumentationTestRunner in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/com.jlptquiz.app-1.apk:/data/app/com.jlptquiz.app-1.apk] E/AndroidRuntime( 843): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3194) E/AndroidRuntime( 843): at android.app.ActivityThread.access$2200(ActivityThread.java:117) E/AndroidRuntime( 843): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:966) E/AndroidRuntime( 843): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 843): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 843): at android.app.ActivityThread.main(ActivityThread.java:3647) E/AndroidRuntime( 843): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 843): at java.lang.reflect.Method.invoke(Method.java:507) E/AndroidRuntime( 843): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) E/AndroidRuntime( 843): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) E/AndroidRuntime( 843): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 843): Caused by: java.lang.ClassNotFoundException: com.jlpt.quiz.app.tests.MyInstrumentationTestRunner in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/com.jlptquiz.app-1.apk:/data/app/com.jlptquiz.app-1.apk] E/AndroidRuntime( 843): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) E/AndroidRuntime( 843): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) E/AndroidRuntime( 843): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) E/AndroidRuntime( 843): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3191) E/AndroidRuntime( 843): ... 10 more W/ActivityManager( 61): Error in app com.jlptquiz.app running instrumentation ComponentInfo{com.jlptquiz.app/com.jlpt.quiz.app.tests.MyInstrumentationTestRunner}: W/ActivityManager( 61): java.lang.ClassNotFoundException W/ActivityManager( 61): java.lang.ClassNotFoundException: com.jlpt.quiz.app.tests.MyInstrumentationTestRunner in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/com.jlptquiz.app-1.apk:/data/app/com.jlptquiz.app-1.apk] I/ActivityManager( 61): Force stopping package com.jlptquiz.app uid=10034 I/Pro
Any idea where I am going to go here?
source share