android 兼容性测试 CTS 测试过程(实践测试验证通过)

中文说明:具体的也可以见中有关Program goals

一、Android的CTS测试,英文为Compatibility Test Suite,意为兼容性测试。只有通过CTS测试的设备才有可能获得Android的商标和享受Android Market的权限;Android的CTS目的与意义:用户在android系统中有更好的用户体验,并且展示android应用的优越性,使得android开发者更容易编写高质量的andorid程序。






Compatibility Test Suite

What is the purpose of the CTS?

The Compatibility Test Suite is a tool used by device manufacturers to help ensure their devices are compatible, and to report test results for validations. The CTS is intended to be run frequently by OEMs throughout the engineering process to catch compatibility issues early.

What kinds of things does the CTS test?

The CTS currently tests that all of the supported Android strong-typed APIs are present and behave correctly. It also tests other non-API system behaviors such as application lifecycle and performance. We plan to add support in future CTS versions to test "soft" APIs such as Intents as well.


CTS是一个免费的,商用级的测试套件,可供下载,CTS运行于台式机的直接连接的设备或仿真器,并执行测试用例。 CTS是一套设计集成到日常工作流程的建筑设备工程师(如通过持续构建系统)中的单元测试。它的目的是揭示不兼容的早期,并确保该软件仍然是整个开发过程中兼容。

Compatibility Test Suite (CTS)

The CTS is a free, commercial-grade test suite, available for download. The CTS represents the "mechanism" of compatibility.

The CTS runs on a desktop machine and executes test cases directly on attached devices or an emulator. The CTS is a set of unit tests designed to be integrated into the daily workflow (such as via a continuous build system) of the engineers building a device. Its intent is to reveal incompatibilities early on, and ensure that the software remains compatible throughout the development process.


pateo@pateo-B86N53X:/$  uname -a
Linux pateo-B86N53X 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux
备注说明: uname -m 如果出现i386 i686 i586则是32位 如果出现amd64 则是64位系统;android官方给出说明froyo/2.2及以后版本默认只支持64-bit
解决方法: 针对你的机器是32位的操作系统
./build/core/ 中的
ifneq (64,$(findstring 64,$(build_arch))) 

ifneq (i686,$(findstring i686,$(build_arch))) 

2、安装jdk 官方:

Installing the JDK

The Sun JDK is no longer in Ubuntu's main package repository. In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.

Java 6: for Gingerbread and newer

$ sudo add-apt-repository "deb lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk


root@pateo-B86N53X:~# sudo update-alternatives --config java
root@pateo-B86N53X:~# sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
  选择       路径                                 优先级  状态
  0            /usr/lib/jvm/java-6-sun/bin/javac       63        自动模式
* 1            /usr/lib/jvm/java-1.5.0-sun/bin/javac   53        手动模式
  2            /usr/lib/jvm/java-6-sun/bin/javac       63        手动模式

update-alternatives: 使用 /usr/lib/jvm/java-6-sun/bin/javac 来提供 /usr/bin/javac (javac),于 手动模式 中。

root@pateo-B86N53X:~# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)

root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# . build/ 
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# lunch 15
pateo@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0$ make

5、Build CTS
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# make cts
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0/out/host/linux-x86/cts# ls

all_cts_core_files_stamp  all_cts_files_stamp  android-cts  temp

root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0/out/host/linux-x86/cts/android-cts/repository/plans# ls
Android.xml  AppSecurity.xml  CTS.xml  Java.xml  Performance.xml  RefApp.xml  Signature.xml  VM.xml


(1)可以从下载最新版本的Compatibility Test Suit;

(2)通过编译Android源代码的方式获得。在android源代码目录下输入make cts命令来编译CTS,之后会在out/host/linux-x86/cts/下生成android-cts文件夹。

          这个文件夹就是 Compatibility Test Suit。

(3)cts的测试主要需要符合Android的兼容性定义文件(CDD) ,CDD列举兼容的Android设备的软件和硬件要求。


Compatibility Definition Document (CDD)

For each release of the Android platform, a detailed Compatibility Definition Document (CDD) will be provided. The CDD represents the "policy" aspect of Android compatibility.


Android 2.3

Android 2.3 is the release of the development milestone code-named Gingerbread. Source code for Android 2.3 is found in the 'gingerbread' branch in the open-source tree.

csdn提供了Android 2.3 Compatibility Definition Document (CDD)相应的翻译可供下载的文档  

6、Running CTS
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0/out/host/linux-x86/bin# ./cts
Listening for transport dt_socket at address: 1337
Android CTS version 2.3_r1
cts_host >  ls  --plan
List of plans (8 in total):
AppSecurity 没有官方说明,猜测是针对Application安全性的测试集合
Performance 包含所有针对性能的测试,随本版的跟新,本测试计划也将更新
RefApp 包含针对参考应用程序的所有测试,随本版的跟新,本测试计划也将更新
Signature 包含所有针对公有APIs的署名测试
CTS 包含21000个测试,这些测试是检验兼容性所必须的,性能测试不包含在本计划中,随本版的跟新,本测试计划也将更新

Android 包含针对androidAPIs的有所测试

备注说明: 在“cts_host >”提示符下输入命令,以下为几个常用的命令
如:start --plan CTS,start --plan plan_name --package package_name 运行一个特定的测试包,如:         start --plan CTS --package android.bluetooth 

官方说明:    cts start --plan CTS -p android.os.cts.BuildVersionTest

官方命令详解:,点击Compatibility Test Suite (CTS) User Manual会有android-cts-manual-r4.pdf文档,此文档里面具体说明了命令的意思

Compatibility Test Suite Manual

The CTS user manual is applicable to any CTS version, but CTS 2.1 R2 and beyond require additional steps to run the accessibility tests.



  • CTSTest组合为TestcaseTestcase再组合为Package,最后由Package组合为Plan

  • CTS可以执行一个Plan,一个Plan的某个Package,一个Plan的某个Test

  • CTS执行的结果以Session_ID来标识一个测试结果。

  • CTS的结果类型result_type包含PassFailTimeoutNoExecuted四种


root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# make sdk

root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# . build/ 
including device/fsl/imx5x/
including device/pateo/yeagle/
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# lunch 15
root@pateo-B86N53X:/work/project/Yeagle_turquoise_3.0# emulator
emulator: WARNING: system partition size adjusted to match image file (128 MB > 66 MB)



archermind@archermind-Lenovo-IdeaPad-Y470:/work/froyo/out/host/linux-x86/sdk/android-sdk_eng.archermind_linux-x86/tools$ emulator

备注说明:如果提示-avd 或  -data file  则可以另一种方式先 . build/,然后lunch 1


archermind@archermind-Lenovo-IdeaPad-Y470:/work/froyo/out/host/linux-x86/cts/android-cts/tools$ gedit startcts



archermind@archermind-Lenovo-IdeaPad-Y470:/work/froyo/out/host/linux-x86/cts/android-cts/tools$ ./startcts 

备注说明:如果运行成功会出现Android CTS version 2.3_r1的字样(我的android的版本是2.3的)。如果有连接设备到PC上还会出现Device(设备ID)connected的字样。这里设 备可以是连接PC的android的机器,也可以是模拟器,如果连接了多个设备的话需加上-d参数,后面跟上设备id来告诉CTS需要测试的设备,通过下面方法查看设备

Android CTS version 2.3_r1
cts_host > 


pateo@pateo-B86N53X:/etc/udev/rules.d$ ls
10-vboxdrv.rules  51-android.rules  51-android.rules.  70-persistent-cd.rules  70-persistent-net.rules  README
pateo@pateo-B86N53X:/etc/udev/rules.d$ cat 51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666",
pateo@pateo-B86N53X:/etc/udev/rules.d$ adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached 

Note:各品牌手机的USBVendor IDs分别见官方:




说明下面两步骤是在之前需run cts之前做的,针对fail的我们需要定位,这个时候我们最好能看到cts的源码,下面为cts的源码获取方式:sudo git clone


fail log: junit.framework.AssertionFailedError: expected:<1> but was:<0> at android.provider.cts.MediaStore_Images_ThumbnailsTest.testQueryExternalMiniThumbnails( 




Verifier是cts的一个补充,可到download下载,CTS Verifier主要测试api和functions,比如不好测的无需人工输入的(如音频质量,加速度等)

Compatibility Test Suite Verifier (CTS Verifier)

The Compatibility Test Suite Verifier (CTS Verifier) is a supplement to the Compatibility Test Suite (CTS), available for download. CTS Verifier provides tests for APIs and functions that cannot be tested on a stationary device without manual input (e.g. audio quality, accelerometer, etc).





  1. Download the CTS.

  2. Attach at least one device (or emulator) to your machine.

  3. For CTS 2.1 R2 and beyond, setup your device (or emulator) to run the accessibility tests:

    1. adb install -r android-cts/repository/testcases/CtsDelegatingAccessibilityService.apk

    2. On the device, enable Settings > Accessibility > Accessibility > Delegating Accessibility Service

  4. For CTS 2.3 R4 and beyond, setup your device to run the device administration tests:

    1. adb install -r android-cts/repository/testcases/CtsDeviceAdmin.apk

    2. On the device, enable all the android.deviceadmin.cts.* device administrators under Settings > Location & security > Select device administrators

  5. Launch the CTS. The CTS test harness loads the test plan onto the attached devices. For each test in the test harness:

  • The test harness pushes a .apk file to each device, executes the test through instrumentation, and records test results.

  • The test harness removes the .apk file from each device.

Once all the tests are executed, you can view the test results in your browser and use the results to adjust your design. You can continue to run the CTS throughout your development process.

When you are ready, you can submit the report generated by the CTS to The report is a .zip archived file that contains XML results and supplemental information such as screen captures.





Writing CTS Tests

CTS tests use JUnit and the Android testing APIs. Review the Testing and Instrumentation tutorial while perusing the existing tests under the cts/tests/tests directory. You will see that CTS tests mostly follow the same conventions used in other Android tests.

Since CTS runs across many production devices, the tests must follow these rules:

  • Must take into account varying screen sizes, orientations, and keyboard layouts.

  • Only use public API methods. In other words, avoid all classes, methods, and fields that are annotated with the "hide" annotation.

  • Avoid relying upon particular view layouts or depend on the dimensions of assets that may not be on some device.

  • Don't rely upon root privileges.

Test Naming and Location

Most CTS test cases target a specific class in the Android API. These tests have Java package names with a cts suffix and class names with the Test suffix. Each test case consists of multiple tests, where each test usually exercises a particular API method of the API class being tested. These tests are arranged in a directory structure where tests are grouped into different categories like "widgets" and "views."

For example, the CTS test for android.widget.TextView is android.widget.cts.TextViewTest found under the cts/tests/tests/widget/src/android/widget/cts directory with its Java package name asandroid.widget.cts and its class name as TextViewTest. The TextViewTest class has a test called testSetText that exercises the "setText" method and a test named "testSetSingleLine" that calls the setSingleLinemethod. Each of those tests have @TestTargetNew annotations indicating what they cover.

Some CTS tests do not directly correspond to an API class but are placed in the most related package possible. For instance, the CTS test,, is in the, because it is network related even though there is no class. You can also create a new test package if necessary. For example, there is an "" test package for tests related to security. Thus, use your best judgement when adding new tests and refer to other tests as examples.

Finally, a lot of tests are annotated with @TestTargets and @TestTargetNew. These are no longer necessary so do not annotate new tests with these.

New Test Packages

When adding new tests, there may not be an existing directory to place your test. In that case, refer to the example under cts/tests/tests/example and create a new directory. Furthermore, make sure to add your new package's module name from its to CTS_COVERAGE_TEST_CASE_LIST in cts/ This Makefile is used by build/core/tasks/ to glue all the tests together to create the final CTS package.

Test Stubs and Utilities

Some tests use additional infrastructure like separate activities and various utilities to perform tests. These are located under the cts/tests/src directory. These stubs aren't separated into separate test APKs like the tests, so the cts/tests/src directory does not have additional top level directories like "widget" or "view." Follow the same principle of putting new classes into a package with a name that correlates to the purpose of your new class. For instance, a stub activity used for testing OpenGL like GLSurfaceViewStubActivity belongs in the android.opengl.cts package under the cts/tests/src/android/opengl directory.

Other Tasks

Besides adding new tests there are other ways to contribute to CTS:

  • Fix or remove tests annotated with BrokenTest and KnownFailure.

Submitting Your Changes

Follow the Android Contributors' Workflow to contribute changes to CTS. A reviewer will be assigned to your change, and your change should be reviewed shortly!



       $ adb shell 
         # monkey -p -v 500


         Monkey 的源码下载地址 :




For CTS Technical Questions

If you have specific issues with the Compatibility Test Suite that require you to disclose information you'd prefer not to be public, you can contact an email address we've set up specifically this purpose: This email address is for cases that require disclosure of confidential information only, so general questions will be directed back to the public android-compatibility list. Note also that this list is for specific technical questions; general inquiries will also be directed back to the android-compatibility list.




发布了0 篇原创文章 · 获赞 0 · 访问量 24
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客