eclipse調試Cts 單項,eclipse調試cts
Cts測試中,單項失敗是常用的事情,想要尋找原因卻比較麻煩,因為cts的command line 雖然提供了單項單獨測試的方法,卻只會輸出結果,最多也就保留了device和host的log,用eclipse來調試還是比較不常見的。今天想到了這個麻煩,研究了下eclipse 調試Cts單項的方法:
首先,Cts的測試主要還是要依賴apk,所以它的調試還是和app的調試很類似的。
1. 通過Cts command line 單獨測試一下失敗項,從log給出的資訊中找到對應的apk。
2. Install這個apk,想辦法讓它跑起來,如果有activity,那am start 就好了。
3. 如果沒有activity 只有instrumentation,那就要用am instrument,這個命令不太常用
am instrument: start an Instrumentation. Typically this target <COMPONENT> is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are: -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with [-e perf true] to generate raw output for performance measurements. -e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a common form is [-e <testrunner_flag> <value>[,<value>...]]. -p <FILE>: write profiling data to <FILE> -w: wait for instrumentation to finish before returning. Required for test runners. --user <USER_ID> | current: Specify user instrumentation runs in; current user if not specified. --no-window-animation: turn off window animations while running. --abi <ABI>: Launch the instrumented process with the selected ABI. This assumes that the process supports the selected ABI.
說明不是很清楚,大概可以看出可以通過 am instrument -r -w XXX 一個instrumentation的名字來跑這個instrumentation。
如何跑單項呢? 要用到-e
例如:
am instrument -r -e class android.provider.cts.MediaStore_FilesTest#testAccess -w com.android.cts.provider/android.support.test.runner.AndroidJUnitRunner
android.provider.cts.MediaStore_FilesTest#testAccess 這一串是不是很熟悉呢,對了,就是cts單項測試時候列印出來的東東,包名類名加方法名。
com.android.cts.provider/android.support.test.runner.AndroidJUnitRunner 這一串呢就是instrumentation的名字,咋知道呢?AndroidManifest裡有。
通過pm list instrumentation 也可以查出來。
ok,只要能讓這個apk跑起來就好辦了,eclipse就可以attach來調試咯。
找個時機去attach也是關鍵,這裡就可以用am set-debug-app來創造時機了。這是一個很有內涵的命令,找個時間再來分析了。