????????Activity ????????
???????????????????

?????????????Activity??package·???????test????


????
????????.png

???????test·??????????FirstActivityTest??????+Test????????ActivityTestCase
????public class FirstActivityTest extends ActivityInstrumentationTestCase2<FirstActivity> {
????private FirstActivity mFirstActivity;
????private TextView mFirstTestTextView;
????public FirstActivityTest() {
????super(FirstActivity.class);
????}
????}
??????????????????????Runner?????????????????????
????????????????κ????????????????????setUp(Runner????)????????????Щ??????и??
????@Override
????protected void setUp() throws Exception {
????super.setUp();
????mFirstActivity = getActivity();
????mFirstTestTextView = (TextView) mFirstActivity.findViewById(R.id.first_test_textview);
????}
??????????????????????????????????????????????
????public void testPreconditions() {
????assertNotNull("mFirstTestActivity is null"?? mFirstActivity);
????assertNotNull("mFirstTestText is null"?? mFirstTestTextView);
????}
????????????????????????? strings.xml ????ж????????????
????public void testFirstTestTextView_labelText() {
????final String expected = mFirstActivity.getString(R.string.hello_world);
????final String actual = mFirstTestTextView.getText().toString();
????assertEquals("mFirstTestText contains wrong text"?? expected?? actual);
????}
????manifest.xml????????????
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner" /><!-- ????????  -->
<activity
android:name="com.speed.androidtest.FirstActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for com.speed.androidtest"
android:targetPackage="com.speed.androidtest" /><!-- targetPackage ???????·??  -->
???????в???????
??????????????Run as ==>Android JUint Test???????????????в?????????testFirstTestTextView_labelText????ж?


??
test_success.png

???????main_activity.xml?е?
????<TextView
????android:id="@+id/first_test_textview"
????android:layout_width="wrap_content"
????android:layout_height="wrap_content"
????android:text="hello" />
??????н??


????
test_error.png

???????textview?е??????????ж????????
????UI???????? Button ???
????setUp??????д
????@Override
????protected void setUp() throws Exception {
????super.setUp();
????setActivityInitialTouchMode(true);
????mSecondTestUIActivity = getActivity();
????mClickMeButton = (Button) mSecondTestUIActivity.findViewById(R.id.second_test_ui_btn);
????}
??????touch mode????????????????б?д????????????????UI????????????????????磬??????????????????????????????????getActivity()??????setActivityInitialTouchMode(true);