错误:测试运行失败:由于'java.lang.ClassNotFoundException,检测运行失败

时间:2013-08-23 09:52:13

标签: android eclipse android-manifest automated-tests robotium

我正在尝试在eclipse中运行简单的测试用例,但我得到了下一个错误:

Android Launch!
adb is running normally.
Performing android.test.InstrumentationTestRunner JUnit launch
Application already deployed. No need to reinstall.
Launching instrumentation android.test.InstrumentationTestRunner on emulator-5554
Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'

包含Robotium lib。 Apk文件已重新签名并已安装。 测试类的名称为“TestClass.java”。包名 - com.android.opera.test。

apk的主要活动和包名称 - com.opera.browser。

我在这里阅读了所有类似的答案,但任何都没有解决我的问题。 代码:

package com.android.opera.test;

import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

@SuppressWarnings("rawtypes")
public class TestClass extends ActivityInstrumentationTestCase2 {
    private static final String TARGET_PACKAGE_ID = "com.opera.browser";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.opera.browser.com.opera.browser";

    private static Class<?> launcherActivityClass;

    private Solo solo;

    static{
        try{
            launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e){
            System.out.println(e.getStackTrace());
            throw new RuntimeException(e);       
        }
    }

    @SuppressWarnings("unchecked")
    public TestClass() throws ClassNotFoundException
    {
        super(TARGET_PACKAGE_ID,launcherActivityClass);
    }   

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testCaseTakeScreenshot() throws InterruptedException {
        solo.takeScreenshot("D://screenTest22!!!!.jpg");
        solo.clickOnScreen(50, 50);
    }

    @Override 
    public void tearDown() throws Exception
    {
        solo.finishOpenedActivities();
    }
}

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.opera.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.opera.browser" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library android:name="android.test.runner" />
    </application>

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

有人能帮助我吗?

0 个答案:

没有答案