0

我正在尝试使用一个非常简单的测试用例使用 Robotium 测试我的应用程序,但它失败了。我已经尝试了一切,但没有任何效果。我的主要活动是谷歌地图活动。我尝试过其他活动,但效果不佳。我的包名是正确的。

这是我试过的:

  • 进口机器人
  • 在订单和出口中检查 Robotium
  • 重启 Eclipse 并清理项目
  • 在清单文件中将 debuggable 设置为 true。

这是清单:

<?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>

这是我的简单测试类:

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

这是我的 LogCat。我也把它放在 pastebin 里,因为它在这里很丑。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
4

1 回答 1

2

下载了您的应用程序。这是我为这个文件准备的测试。反正我没有资源,所以肯定有点不同:

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

它对我有用: 在此处输入图像描述 附加项目: http ://www.speedyshare.com/hf3hP/MyApkTest.zip

于 2013-04-06T11:10:15.550 回答