0

I am trying to test my application with Robotium using an extremely simple test case but it fails. I have tried everything and nothing works. My main activity is a Google Maps Activity. I've tried other activities but they don't work as well. My package name is correct.

This I have tried:

  • Importing Robotium
  • Checking Robotium in Order and Export
  • Restart Eclipse and Clean Project
  • Set debuggable to true in the manifest file.

Here is the Manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.app.neatspots.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17"/> <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.app.neatspots" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:debuggable="true"> <uses-library android:name="android.test.runner" /> </application> </manifest> 

Here is my simple test class:

package android.test; import com.app.neatspots.MainActivity; import com.jayway.android.robotium.solo.Solo; import android.test.ActivityInstrumentationTestCase2; public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { private Solo solo; public MainActivityTest() { super(MainActivity.class); this.solo = new Solo(getInstrumentation(), getActivity()); } protected void setUp() throws Exception { super.setUp(); } public void testClick() { solo.assertCurrentActivity("Check on first activity", MainActivity.class); } } 

Here is my LogCat. I put it in pastebin as well because it's ugly here. http://pastebin.com/GuvcRuHg

04-05 20:54:33.402: W/dalvikvm(19668): Class resolved by unexpected DEX: Lcom/app/neatspots/MainActivity;(0x414e7fe0):0x2068c8 ref [Lcom/google/android/gms/maps/GoogleMap$OnMapLongClickListener;] Lcom/google/android/gms/maps/GoogleMap$OnMapLongClickListener;(0x414e7fe0):0x23ac70 04-05 20:54:33.402: W/dalvikvm(19668): (Lcom/app/neatspots/MainActivity; had used a different Lcom/google/android/gms/maps/GoogleMap$OnMapLongClickListener; during pre-verification) 04-05 20:54:33.402: I/dalvikvm(19668): Failed resolving Lcom/app/neatspots/MainActivity; interface 818 'Lcom/google/android/gms/maps/GoogleMap$OnMapLongClickListener;' 04-05 20:54:33.402: W/dalvikvm(19668): Link of class 'Lcom/app/neatspots/MainActivity;' failed 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): Cannot load class. Make sure it is in your apk. Class name: 'com.app.neatspots.MainActivity'. Message: com.app.neatspots.MainActivity 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): java.lang.ClassNotFoundException: com.app.neatspots.MainActivity 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.Class.classForName(Native Method) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.Class.forName(Class.java:217) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.SimpleCache.get(SimpleCache.java:31) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:358) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3932) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.app.ActivityThread.access$1300(ActivityThread.java:127) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.os.Handler.dispatchMessage(Handler.java:99) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.os.Looper.loop(Looper.java:137) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at android.app.ActivityThread.main(ActivityThread.java:4507) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.reflect.Method.invoke(Method.java:511) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at dalvik.system.NativeStart.main(Native Method) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): Caused by: java.lang.NoClassDefFoundError: com/app/neatspots/MainActivity 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): ... 26 more 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at dalvik.system.DexFile.defineClass(Native Method) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:195) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at dalvik.system.DexPathList.findClass(DexPathList.java:315) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 04-05 20:54:33.407: W/ClassPathPackageInfoSource(19668): ... 26 more 04-05 20:54:33.442: D/dalvikvm(19668): GC_CONCURRENT freed 498K, 7% free 9028K/9607K, paused 2ms+2ms 04-05 20:54:33.492: D/dalvikvm(1988): GC_CONCURRENT freed 1602K, 35% free 25226K/38279K, paused 3ms+8ms 04-05 20:54:33.502: E/DataRouter(1828): usb connection is true 04-05 20:54:33.502: E/DataRouter(1828): DSR is ON. Don't send DTR ON. 04-05 20:54:33.502: D/dalvikvm(19668): GC_CONCURRENT freed 487K, 6% free 9052K/9607K, paused 1ms+2ms 04-05 20:54:33.592: D/dalvikvm(19668): GC_CONCURRENT freed 537K, 6% free 9146K/9671K, paused 2ms+8ms 04-05 20:54:33.662: D/dalvikvm(19668): GC_CONCURRENT freed 614K, 7% free 9066K/9735K, paused 2ms+2ms 04-05 20:54:33.692: I/FMRadioService(1988): *** mReceiver: VOLUME_CHANGED_ACTION 04-05 20:54:33.692: I/FMRadioService(1988): stream: 3 04-05 20:54:33.692: I/FMRadioService(1988): volume: 15 04-05 20:54:33.692: I/FMRadioService(1988): *** mReceiver: VOLUME_CHANGED_ACTION 04-05 20:54:33.692: I/FMRadioService(1988): stream: 9 04-05 20:54:33.692: I/FMRadioService(1988): volume: 15 04-05 20:54:33.692: I/FMRadioService(1988): *** mReceiver: VOLUME_CHANGED_ACTION 04-05 20:54:33.692: I/FMRadioService(1988): stream: 10 04-05 20:54:33.692: I/FMRadioService(1988): volume: 0 04-05 20:54:33.692: I/FmRadioController(1988): Jni player_SetVolume :0 04-05 20:54:33.692: I/FmRadioController(1988): ---Jni player_SetVolume--- 04-05 20:54:33.692: I/FmRadioController(1988): Jni player_muteOn 04-05 20:54:33.692: I/FmRadioController(1988): Jni player_muteOn 04-05 20:54:33.722: D/dalvikvm(19668): GC_CONCURRENT freed 493K, 7% free 9085K/9735K, paused 1ms+2ms 04-05 20:54:33.787: D/dalvikvm(19668): GC_CONCURRENT freed 530K, 7% free 9066K/9735K, paused 1ms+2ms 04-05 20:54:33.842: D/dalvikvm(19668): GC_CONCURRENT freed 510K, 7% free 9068K/9735K, paused 1ms+2ms 04-05 20:54:33.852: I/TestSuiteBuilder(19668): Failed to create test. 04-05 20:54:33.852: I/TestSuiteBuilder(19668): java.lang.reflect.InvocationTargetException 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at java.lang.reflect.Constructor.constructNative(Native Method) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:371) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3932) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.app.ActivityThread.access$1300(ActivityThread.java:127) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.os.Handler.dispatchMessage(Handler.java:99) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.os.Looper.loop(Looper.java:137) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.app.ActivityThread.main(ActivityThread.java:4507) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at java.lang.reflect.Method.invokeNative(Native Method) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at java.lang.reflect.Method.invoke(Method.java:511) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at dalvik.system.NativeStart.main(Native Method) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): Caused by: java.lang.NullPointerException 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:94) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): at android.test.ListLocationsTest.<init>(ListLocationsTest.java:14) 04-05 20:54:33.852: I/TestSuiteBuilder(19668): ... 18 more 04-05 20:54:33.852: I/TestRunner(19668): started: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests) 04-05 20:54:33.872: I/TestRunner(19668): finished: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests) 04-05 20:54:33.872: I/TestRunner(19668): passed: testSuiteConstructionFailed(android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests) 04-05 20:54:33.887: D/AndroidRuntime(19644): Shutting down VM 04-05 20:54:33.887: I/ActivityManager(1988): Force stopping package com.app.neatspots uid=10139 04-05 20:54:33.887: I/ActivityManager(1988): Killing proc 19668:com.app.neatspots/10139: force stop 
10
  • look here: stackoverflow.com/questions/3621163/… Commented Apr 5, 2013 at 20:55
  • Btw it's not a problem, if you have only one test method, however you should instantiate solo in setUp method. Also you have missed tearDown. Commented Apr 5, 2013 at 20:57
  • I was watching the Robotium video tutorial provided by the official website and that's what they do :S Commented Apr 5, 2013 at 21:04
  • Also, my Android application is running perfectly fine. It's on the market... Commented Apr 5, 2013 at 21:05
  • I'm sure, you are doing it wrong. This video is obsolete. code.google.com/p/robotium/wiki/Getting_Started Commented Apr 5, 2013 at 21:30

1 Answer 1

2

Downloaded your application. Here is the test I've prepared for this file. Anyway I don't have sources, so it must be a bit different:

package com.app.neatspots.test; import android.app.Activity; import android.test.ActivityInstrumentationTestCase2; import com.jayway.android.robotium.solo.Solo; public class Test extends ActivityInstrumentationTestCase2<Activity> { private static final String LAUNCHER_ACTIVITY_CLASSNAME = "com.app.neatspots.MainActivity"; private static Class<?> launchActivityClass; static { try { launchActivityClass = Class.forName(LAUNCHER_ACTIVITY_CLASSNAME); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } private Solo solo; @SuppressWarnings("unchecked") public Test() { super((Class<Activity>) launchActivityClass); } @Override public void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); } @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); super.tearDown(); } public void testRecorded() throws Exception { solo.waitForActivity("MainActivity"); solo.sleep(5000); } } 

It works for me: enter image description here Attached project as well: http://www.speedyshare.com/hf3hP/MyApkTest.zip

Sign up to request clarification or add additional context in comments.

4 Comments

I don't know, what your problem is related to. I gave you only hints with constructor and setUp, as I cannot see your environment, project...
I think it was ActivityInstrumentationTestCase2<Activity> in the class signature as I put MainActivity as opposed to Activity
Don't think so, if MainActivity extends Activity, it's correct as well
You didn't get it. His test didn't even run. My finished without problems. It doesn't matter what is inside test method at all in this case...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.