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?
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 );
精彩评论