0
package com.test.android.calculator2;
import android.app.Activity;
import com.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
@SuppressWarnings("unchecked")
public class TestApk extends ActivityInstrumentationTestCase2 {
private static final String TARGET_PACKAGE_ID="com.android.calculator2";
private static final String
LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.android.calculator2.Calculator";
private static Class <?> launcherActivityClass;
static {
try {
Activity act = new Activity();
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
// @SuppressWarnings("unchecked")
public TestApk()throws ClassNotFoundException {
super(TARGET_PACKAGE_ID,launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation());
}
public void testCanOpenSettings() {
solo.getActivityMonitor();
getActivity();
solo.sendKey(Solo.DOWN);
solo.goBack();
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
файл манифест, как этот
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.android.calculator2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="19" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.calculator2" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
Но целевой пакет и тестовый пакет не должны быть одинаковыми. И я тестирую встроенный калькулятор. –
Это, безусловно, имеет смысл. В этом случае вам нужно создать пакет 'com.android.calculator2'beforehand, иначе ваша программа не сможет его найти. – 1r0n1k