*
* @Override
* protected void setUp() throws Exception {
* String tag = "setUp";
* Log.e(tag, "init all var....");
* newActivity = getActivity();
* button1 = (Button) newActivity.findViewById(R.id.Button01);
* button2 = (Button) newActivity.findViewById(R.id.Button02);
* }
* /**
* * Testing the button is focused or not
* */
* public void testButtonFocus() {
* String tag = "testButtonFocus";
* Log.e(tag, "start the button focus...");
* assertTrue("Button1 is focused", button1.isFocused());
* Log.e(tag, "send the down key event...");
* sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
* assertTrue("Button2 is focused", button2.isFocused());
* }
*
* /**
* * Testing the add method in actvity
* */
* public void testAdd(){
* String tag ="testAdd";
* Log.e(tag, "Test the add method in NewActivity...");
* int i = newActivity.add(2, 5);
* assertEquals(7, i);
* }
*
* }
五、配置Manifest.xml文件
Java代碼

*
* * package="cc.androidos.activity" android:versionCode="1" * android:versionName="1.0"> * * * * * * * * * * * * * * * * * android:label="Test New Activty" android:name="android.test.InstrumentationTestRunner"> *
*
* * package="cc.androidos.activity" android:versionCode="1" * android:versionName="1.0"> * * * * * * * * * * * * * * * * * android:label="Test New Activty" android:name="android.test.InstrumentationTestRunner"> *
Java代碼

# E:\android\android-sdk-windows-1.5_pre\tools>adb shell am instrument -w cc.andro
# idos.activity/android.test.InstrumentationTestRunner
# 如果你配置了Android環境變量,直接使用:
# adb shell am instrument -w cc.androidos.activity/android.test.InstrumentationTestRunner
# 語法:adb shell am instrument -w <被測試的類的包名>/android.test.InstrumentationTestRunner
文章來源于領測軟件測試網 http://www.kjueaiud.com/