开发者

Code in a test app that interacts with a View of the AUT must run in the main apps thread but is .runOnUiThread always needed?

开发者 https://www.devze.com 2023-02-09 00:59 出处:网络
Whilereading thetesting tutorial athttp://developer.android.com/resources/tutorials/testing/activity_test.html

While reading the testing tutorial at http://developer.android.com/resources/tutorials/testing/activity_test.html

I began to wonder why is the below code needed.

public void testSpinnerUI() {

    mActivity.runOn开发者_StackOverflowUiThread(
      new Runnable() {
        public void run() {
          mSpinner.requestFocus();
          mSpinner.setSelection(INITIAL_POSITION);
        } // end of run() method definition
      } // end of anonymous Runnable object instantiation
    ); // end of invocation of runOnUiThread

Why is it not better to use sendKeys( KeyEvent.KEYCODE_DPAD_DOWN ); alone to set the focus?

Such as here

http://mihaifonoage.blogspot.com/2010/01/unit-and-functional-testing-in-android.html

public void testAdd() throws Throwable {

        //First field value
        sendKeys( KeyEvent.KEYCODE_3 );
        sendKeys( KeyEvent.KEYCODE_PERIOD );
        sendKeys( KeyEvent.KEYCODE_5 );
0

精彩评论

暂无评论...
验证码 换一张
取 消