Andriod CTS

上一篇 / 下一篇  2011-05-09 12:02:47 / 个人分类:自动化测试


1. 什么是CTS

CTS is Compatibility Test Suite, 兼容性测试包。手机设备需要通过Android的兼容性测试(CTS),以确保在android上开发的程序在手机设备上都能运行。你的设备只有满足CDD的规定并且通过CTS,才有可能获得Android的商标和享受Android Market的权限。这里有可能指的是需要你自己去向google申请的。


2. Android CTS build in linux:

    (1).$: . build/envsetup.sh

(2).  git下载的源码里包含cts,位置在$ANDROID/cts目录下(android2.1以后版本)

       如果没有也可以从此处下载git://android.git.kernel.org/platform/cts.git(源码70M左右)
$: make cts
此时生成测试计划,测试包,测试用例,和测试报告生成的目录
(3). 指定SDK_ROOT目录:
export SDK_ROOT=.../Android_sdk_linux/主要因为要用到里面的一些库,如tools\lib\ddmlib.jar
(4). 运行startcts          will enter mode of cts test. OK

3. Android CTS build in Window:
(1). download CTS or Copy CTS package in linux. - upzip
(2). 设置的环境变量 或修改 cts\android-cts\tools\startcts:
新建SDK_ROOT= .../android-sdk-windows/
,或修改cts\android-cts\tools\startcts:
  SDK_ROOT=../android-sdk-windows/
    (3). 在终端运行如下命令进入CTS shell:

       java -Xmx512M -cp C:\android-cts\tools\cts.jar;C:\android-cts\tools\hosttestlib.jar;C:\android-cts\tools\junit.jar;D:\android-sdk-windows\tools\lib\ddmlib.jar com.android.cts.TestHost C:\android-cts\repository\host_config.xml

如果使用的是android-cts-2.2_r4-x86.zip,-cp选项中需要多一个C:\android-cts\tools\lib\CtsTestAnnotationsHostLib.jar,可参考startcts脚本。


4. Usage of CTS

    

方法1:一般使用的方法

cts_host > ls --plan                列出所有plan

out/host/linux-x86/cts/android-cts/repository/plans中有plan的具体内容

cts_host > start --plan VM    运行某个plan

测试结果在out/host/linux-x86/cts/android-cts/repository/results目录下,用浏览器看时间目录下的xml文件即可

注意在改动cts后,还要make cts重新编译,若只在cts目录中编译不能生效

cts_host > ls -p   看当前可用的用例包

cts_host > start  --plan  Android           //test    Android  API
cts_host > start  --plan  CTS               //contains all tests and will run ~21,000 tests on your device  
cts_host > start  --plan  Java             //test   Java  core  libary

cts_host > start --plan Android -p android.app        只运行某个用例包,节约时间

cts_host > start --plan Android -p android.app -t android.app.cts.AlertDialogTest#testAlertDialog

只运行某个用例包中的某个用例

cts_host > start --plan Android -t android.app.cts.DialogTest#testOnKeyDownKeyUp

start test android.app.cts.DialogTest#testOnKeyDownKeyUp

==============================================================

Test package: android.app

android.app.cts.DialogTest#testOnKeyDownKeyUp....(pass)

==============================================================

Time: 4421.515s


运行一个测试包:


cts_host > start --plan Android -p android.app.cts.InstrumentationTest

start java package android.app.cts.InstrumentationTest

==============================================================

Test java package contained in test package android.app: android.app.cts.InstrumentationTest

android.app.cts.InstrumentationTest#testAllocCounting...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnCreate...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnDestroy...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnNewIntent...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnPause...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnPostCreate...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnRestart...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnRestoreInstanceState...(pass)

android.app.cts.InstrumentationTest#testCallActivityOnResume...(pass)


方法2:遇到问题时方便调试的方法

$ adb install out/target/product/xxxx/data/app/SginatureTest.apk 安装某个用例包

$ adb shell pm list instrumentation          pm用于管理package,看当前机器安装了什么用例

$ adb shell am instrument -w android.tests.sigtest/.InstrumentationRunner             am用于管理activity   运行某一用例

$ adb shell am instrument -e class android.app.cts.AlertDialogTest#testAlertDialog -w com.android.cts.app/android.test/InstrumentationCtsTestRunner          单独运行一个小case

如果在一个时间很长的plan(如Android)中,某处错了,而错误信息又不全,需要单独跑一个小case,用-e指明class明就可以节约很多时间


结果在repository/results中,放在一个文件夹里,名字是你测试开始的时间。


分析的方法有两种:


1、可以直接从Failure Details找原因;(个人感觉应该难度较大)


2、结合源代码以及Failure Details的信息找原因


第二种方法牵扯到找测试源代码的问题,这就要对CTS源码目录以及相应生成物的命名有一定的了解。



5.说明
       a)bin/cts是一个脚本,它使用adb来测试,测试程序及测试用例由java语言编写
       b)cts主函数为cts/tools/host/src/com/android/cts/TestHost.java

6.在“cts_host >”提示符下输入命令,以下为几个常用的命令 
help 查看所有命令
exit 退出
ls -p 列出所有的测试包

ls --plan 列出所有的测试方案
start --plan plan_name 运行一个测试方案,如:start --plan CTS
start --plan plan_name --package package_name 运行一个特定的测试包,如:start --plan CTS --package android.bluetooth


-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by semicolons (;). Specifying -classpath or -cpoverrides any setting of the CLASSPATH environment variable.

If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.)


TAG:

 

评分:0

我来说两句

Open Toolbar