2、instrumentation implementation通過AndroidManifest.xml中的<instrumentation>標籤進行描述
3、instrumentation有些類似windows中的hook函數,在系統與應用程序之間安裝了個竊聽器。
如何實現一個button的點擊?
測試類繼承InstrumentationTestCase 該類在android.test包內
重寫setUp函數
@Override
protected void setup() throws Exception{
super.setUp();
Intent intent=new Intent();
intent.setClassName("被測app包名","被測app主Activity類名")
getInstrumentation().startActivitySync(Intent intent)//得到被測app的mainActivity
getInstrumentation方法得到一個instrumentation實例,該類是android.app包裏面的一個類,在被測app啓動時該類已經被初始化了,直接用getInstrumentation方法得到該實例,無需再去new一個。
//Execute a call on the application's
main thread, blocking until it is complete.
getInstrumentation().runOnMainSync(Runnable runner)
注:runner裏封裝一個view,run方法調用該view自己的click事件
view.PerformClick(); //調用view的click事件