Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid unit test - InstrumentationTestRunner subclass not found
    primarykey
    data
    text
    <p>I'm having another problem with using a subclass of InstrumentationTestRunner.</p> <p>Here's the code for the subclass: </p> <pre><code>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(); } } </code></pre> <p>Here's the unit test:</p> <pre><code>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) { // TODO Auto-generated catch block e.printStackTrace(); } mContext = this.getInstrumentation().getContext(); } public void testRandomNumberEqaulsOne() { utils = (Utils) this.getActivity(); int randNum = Utils.genRandomNumber(1, 1); Integer actual = Integer.valueOf(randNum); Integer expected = Integer.valueOf(1); Assert.assertSame(expected, actual); } } </code></pre> <p>Here's the manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jlptquiz.app" android:versionCode="1" android:versionName="1.0"&gt; &lt;application android:name="AppState" android:debuggable="true" android:clearTaskOnLaunch="true" android:icon="@drawable/ic_icon" android:label="@string/app_name"&gt; &lt;activity android:name="JlptQuizStartActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="QuestionActivity"&gt;&lt;/activity&gt; &lt;activity android:name="AnswerActivity"&gt;&lt;/activity&gt; &lt;activity android:name="SettingsActivity"&gt;&lt;/activity&gt; &lt;uses-library android:name="android.test.runner" /&gt; &lt;/application&gt; &lt;instrumentation android:label="AllTests" android:name="com.jlpt.quiz.app.tests.MyInstrumentationTestRunner" android:targetPackage="com.jlptquiz.app"/&gt; &lt;uses-sdk android:minSdkVersion="5" /&gt; &lt;/manifest&gt; </code></pre> <p>And the run configuration, an android junit test configuration, specifies MyInstrumentationTestRunner as the ImplementationTestRunner. </p> <p>But, I'm coming up with a class not found exception on the MyInstrumentationTestRunner, as per logcat:</p> <pre><code>/AndroidRuntime( 835): &gt;&gt;&gt;&gt;&gt;&gt; AndroidRuntime START com.android.internal.os.RuntimeInit &lt;&lt;&lt;&lt;&lt;&lt; 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 </code></pre> <p>Any idea where I'm going off the tracks here? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload