src code:
package com.june.test;
import com.jayway.android.robotium.solo.Solo;
import android.app.Instrumentation;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
public class LaunchApp extends ActivityInstrumentationTestCase2 {
private static final String TARGET_PACKAGE = "com.app.package";
private static final String LAUNCHER_ACTIVITY = "com.app.package.MainActivity";
private static Class<?> className;
Instrumentation mInst;
private Solo solo;
static {
try {
className = Class.forName(LAUNCHER_ACTIVITY);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public LaunchQQ() throws ClassNotFoundException {
super(TARGET_PACKAGE, className);
}
@Override
protected void setUp() throws Exception {
mInst = getInstrumentation();
solo = new Solo(mInst, getActivity());
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
public void testCanOpenSettings() throws Exception {
SystemClock.sleep(5000);
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
SystemClock.sleep(1000);
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
SystemClock.sleep(1000);
mInst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
SystemClock.sleep(1000);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.june.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="3" />
<instrumentation android:targetPackage="com.app.package"
android:name="android.test.InstrumentationTestRunner" />
</manifest>