1. 程式人生 > >Android測試原理(二)

Android測試原理(二)

// 在測試環境下啟動Activity
    mActivity = getActivity();

    // 得到這個Activity中的主要UI控制代碼,一個Spinner   
 mSpinner = (Spinner)mActivity.findViewById(com.android.example.spinner.R.id.Spinner01);

    //獲取Spinner的位置 
    mActivity.setSpinnerPosition(TEST_STATE_DESTROY_POSITION);

    // Stop theactivity - The onDestroy() method should save the state of the Spinner 停止activity,呼叫onDestroy方法儲存Spinner的狀態
    mActivity.finish();

    // Re-start theActivity - the onResume() method should restore the state of the Spinner重新啟動Activity,onResume()方法應該儲存Spinner
    mActivity = getActivity();

    // Get theSpinner's current position 獲取Spinner的位置
    int currentPosition = mActivity.getSpinnerPosition();

    // Assert thatthe current position is the same as the starting position判斷當前的位置和啟動之前的位置是不是一樣的
    assertEquals(TEST_STATE_DESTROY_POSITION, currentPosition);