您的位置:首页 > 编程语言 > Java开发

eclipse调试Cts 单项

2015-05-29 13:55 316 查看
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来创造时机了。这是一个很有内涵的命令,找个时间再来分析了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: