我想寫一個簡單的測試應用程序在JUnit中運行。我一直無法讓clickView點擊正確的視圖。以下是一些可用於SDK附帶的SkeletonActivity示例應用程序的示例代碼。clickView如何正確使用?
public class SkeletonInstrumentation extends ActivityInstrumentationTestCase2<Activity>{
private Activity act;
private Button bClear;
private Button bBack;
private EditText eMain;
public SkeletonInstrumentation(){
super("com.example.android.skeletonapp", Activity.class);
}
public void setUp() {
String app = this.getInstrumentation().getTargetContext().getPackageName();
this.setActivityInitialTouchMode(true);
act = this.launchActivity(app, SkeletonActivity.class, Bundle.EMPTY);
bClear = (Button) act.findViewById(R.id.clear);
bBack = (Button) act.findViewById(R.id.back);
eMain = (EditText) act.findViewById(R.id.editor);
}
public void testClick()
{
TouchUtils.clickView(this, bClear);
}
public void testSendKeys()
{
act.runOnUiThread(
new Runnable(){
public void run(){
bClear.clearFocus();
eMain.requestFocus();
}
}
);
this.sendKeys("A B C D E F G ENTER");
}
}
testClick運行,但點擊該有當焦點在活動開始和結束造就了屏幕上的鍵盤主要的EditText視圖。我希望它能夠點擊EditText下方的「清除」按鈕。有人能告訴我這裏有什麼問題嗎?
請您詳細說明一下嗎? – 2012-06-28 15:35:24