最近接触到CTS,据传不懂CTS就不算一个合格的android开发人员,我之前一直没见周边谁用过,作为一个产品开发的android人员,我还是太年轻~
撰写不易,转载请注明出处:http://blog.youkuaiyun.com/jscese/article/details/40650001#t11
概念:
Compatibility Test Suite (CTS) 兼容性测试组,是由google提供的一套测试框架,含有很多测试用例,
框架用于管理测试用例在真机设备或者模拟器上的执行,那些用例全是用java写的apk,通过运行这些apk得到的结果来测试系统平台的兼容性与稳定性.
Compatibility Definition Document (CDD) 一个定义标准,系统需要符合软件以及硬件相关参数.
你可以把测试结果发送给cts@android.com。当你提交了一个CTS报告时,你还可以要求访问Android Market。
配置:
有android源码的可以直接在源码下 make cts ,最后会生成 /out/host/linux-x86/cts/android-cts
还可以去 http://source.android.com/compatibility/downloads.html 上面下载google提供的各个版本的 CTS组件,解压出来android-cts目录需要版本对应!
目录结构如下:
其中docs为空,
repository目录下有plans . testcases
tools 目录下就是启动 cts console 的工具包,由 cts-tradefed 脚本启动!其中有个README
网上的配置五花八门,直接看这个简单明了:
Configuring cts-tradefed
------------------------
1. Ensure 'adb' is in your current PATH. adb can be found in the
Android SDK available from http://developer.android.com
Example:
PATH=$PATH:/home/myuser/android-sdk-linux_x86/platform-tools
2. Follow the 'Setting up your device' steps documented in the
CTS User Manual. The CTS User Manual can be downloaded at
http://source.android.com/compatibility/downloads.html
3. Connect the device to the host machine.
4. Ensure device is visible via 'adb devices'
Using cts-tradefed
-------------------
To run a test plan on a single device:
1. Make sure you have at least one device connected
2. Launch the cts-tradefed console by running the 'cts-tradefed' script at
android-cts/tools/cts-tradefed
3. Type:
'run cts --plan CTS' to run the default CTS plan
Some other useful commands are
To run a test package:
'run cts --package <packagename>'
To run a test class:
'run cts --class <full test class name>'
To shard a plan test run on multiple devices
'run cts --plan CTS --shards <number of shards>
note: all connected devices must be running the same build
For more options:
'run cts --help'
CTS Tradefed Development
------------------------
See http://source.android.com for instructions on obtaining the Android
platform source code and setting up a build environment.
The source for the CTS extensions for tradefed can be found at
<android source root>/cts/tools/tradefed-host
The source for the tradefed framework can be found on the 'tradefed' branch.
Perform these steps to build and run cts-tradefed from the development
environment:
cd <path to android source root>
make cts
cts-tradefed
google的README写的很明白了,需要终端能够使用 adb 这个在google提供的SDK中是有的,还给出来了下载链接,然后设置到环境变量PATH中!
可以看下cts-tradefed 这个脚本:
checkPath adb
checkPath java
# check java version
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep '[ "]1\.6[\. "$$]')
if [ "${JAVA_VERSION}" == "" ]; then
echo "Wrong java version. 1.6 is required."
exit
fi
可以看到 是需要 jdk 1.6 以上的支持的!
android源码下的 cts 可能不是最新的,所以最好是去上面提到的google官网去下载对应的 cts 组件!
使用:
启动:
首先打开TV的adb调试开关,ubuntu通过adb connect TV_IP 连接,android-cts下执行cts-tradefed脚本进入cts控制台:
可以看到在cts-tf下使用 l d 命令查看到了 设备的相关信息.
命令:
使用help查看:
可以看到支持的命令集!
其中版本为4.2_r4,定义在/cts/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java 中
使用 l p 查看可测试的计划:
cts-tf > l p
CTS-TF
CTS
VM-TF
AppSecurity
PDK
Java
Android
Signature
这些都是存在 android-cts/repository/plans 下
一个plan中包含多个package ,每一次执行 run cts 都会分配一个 Session 号,从 0开始..
l d 显示连接的设备, l packages 显示可测试的包 , l r 显示记录结果
run cts -p package_name 单独测试package_name包
run cts --continue-session sessionID --disable-reboot
根据sessionID 继续进行测试,不重启 ,因为重启 adb就断掉了!
run cts -c com.class_name -m methmod_name 单独测试某个类的方法 -c 后面跟类名全路径 –m 后面跟方法名
其它命令可以看注释,不多做解释!
准备:
如果需要测试media相关的包,可在google官网下载 CTS Media 1.0 放到sdcard的test目录.
另外需要做的准备有:
安装cts测试需要的apk到目标板:CtsDelegatingAccessibilityService.apk,CtsDeviceAdmin.apk
(这两个APK可以在cts源码目录的testcase中找到)
系统setting的配置
(如果项目删除了默认的setting或者深度修改了,可以用google的原生setting替代原有的setting来进行设置)
进入settings打开Wi-Fi并连接AP (AP需要连外网)
进入settings->Security->Screenlock设为None
进入settings->Security->Deviceadministrators->Enable两个选项
进入Language&input->language设为English(UnitedStates)
进入settings->Display->Sleep设为30minutes或None
进入settings->Accessibility->EnableDelegating Accessibility Service
进入settings->Developeroptions->Enable USB debugging、Stay awake、Allowmock locations
手动设置时间,并将时区调为北京,设置国家为china
这样就可以运行 run cts * 进行测试啦!
结果:
测试完之后的结果保存在 /android-cts/repository/results/2014.10.31_11.53.42/testResult.xml 中
可以看到结果就四种:[pass/fail/notExecuted/timeout]
如果我们的硬件上并不支持某个功能模块的时候,我们可以在testResult.xml中修改 result="fail" 为 result="notExecuted"
如果是fail的肯定还有这样的附加信息:
<Test name="testPlay00" result="fail" starttime="星期五 十月 31 12:01:24 CST 2014" endtime="星期五 十月 31 12:01:26 CST 2014">
<FailedScene message="junit.framework.AssertionFailedError: playback /mnt/sdcard/test/bbb_short/176x144/3gp_h263_libfaac/bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp
at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlayback(MediaPlayerStressTest.java:161)
">
<StackTrace>junit.framework.AssertionFailedError: playback /mnt/sdcard/test/bbb_short/176x144/3gp_h263_libfaac/bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp
at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlayback(MediaPlayerStressTest.java:161)
at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlaybackShort(MediaPlayerStressTest.java:165)
at android.mediastress.cts.H263QcifShortPlayerTest.testPlay00(H263QcifShortPlayerTest.java:49)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
</StackTrace>
</FailedScene>
</Test>
可以看到还有堆栈信息,可用于查找定问fail原因!
添加testcase:
我们可以在源码/cts/tests/tests/下面看到所有的testcase
网上的方法,这里借用记录如下:
配置Testcase
结构如下:<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.cts.XXX">
<uses-permissionandroid:name="android.permission.DISABLE_KEYGUARD" />
<application>
<uses-libraryandroid:name="android.test.runner" />
</application>
<instrumentationandroid:name="android.test.InstrumentationCtsTestRunner"
android:targetPackage="com.android.cts.stub"
android:label="CTStests of android.XXX"/>
</manifest>