我正在尝试在 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'
包括机器人库。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>
有人可以帮助我吗?