资料收藏

 Android CTS 测试研究
前言¶

从各种渠道了解到 Android CTS 测试, 是一种类似于 Windows Mobile LTK 的测试。
大体 Google 一下, 发现关于 CTS 的 信息非常至少, 只说它有两万多个测试用例。
然后它只对 OHA 成员开发。

本着不抛弃,不放弃的原则,继续 Google...
终于发现了参考1:Cezary Statkiewicz's blog。
搞笑的是该 Blog 的前言部分还写着 CTS 不开放。 后面又纠正了 Google 刚刚开放 CTS 信息(见参考2)。

大喜!

先学习¶

原来 Google 定义了一个兼容性规范(Compatibility Definition), 而 CTS 就是用于确保某个测试符合该规范。

从而基于 Android 的 应用程序能够在基于同一 API 版本的各种设备上运行。
由于我们使用Android 2.1 (Eclair), 所以从参考2 下载到 Android 2.1 的

Compatibility Definition, 大体阅读一下, 它定义了一些需求:

数据: 必须实现一种无线连接, 速率达到 200Kbit/Sec
Camera: 至少 2M pixels
重力加速: 必须有, 3维, >50Hz
指南针: 必须有, 3纬, >10Hz
GPS: 必须有
内存: 至少 92M (不包括专用内容)
Nand: /data 分区至少 290M
性能: 启动 时间: 浏览器 < 1300ms
MMS/SMS < 700ms
AlarmClock < 650ms
第二次启动一个应用的时间不能超过第一次启动时间。
CTS 测试: 必须通过最新的 CTS
升级: 必须有一种办法可以升级全系统。 可以为:
OTA
USB
SD 卡

看来 Android 是在不断往高端方向走。 不过想想也正常,今天的高端就是明天的低端!

Quick Start¶
参考2 的 User Manual 似乎是针对 1.6 的, 其中提到 CTS 是单独下载的一个包。
而参考1 则说从 source code 中编译而来。
先按照参考1简单运行一下。
1) 获取 2.1 代码, 并先做一个基本的编译(不知是否需要)

2) 编译 cts:

    cd ~/mydroid
    . build/evnsetup.sh
    make cts
3)  启动 emulator (或者 device, 不过可能需要按照 User Manual 设置一下)
4) 将 ~/mydroid/out/host/linux-x86/bin 加到路径
5)  adb start-server
6) cts

进入 cts 交互环境, 可以敲入 help 看各种命令:cts_host > help
这里是quick start,所以不详解。
7) 在 shell 下直接以非交互模式运行一下:
$ cts start --plan Signature
该测试用例比较少,发现两分钟可以运行通过。 像 Android 测试方案就比较耗时间了。

参考¶
1. 某大牛的 Blog 文章
http://bitbar.com/blog/44/using-androids-compatibility-test-suite
2. Android 官方 论坛:
http://source.android.com/compatibility/downloads.html

Android CTS 测试研究之二

作者: 宋立新

Email : zjujoe@yahoo.com


前言

继续较深入了解 CTS 的细节
先研究一下具体用法

命令行下敲 cts 进入命令行 ,
先看一下帮助

Help 一下

cts_host > help

Usage: command options

Avaiable commands and options:

  Host:

    help: show this message

    exit: exit cts command line

  Plan:

    ls --plan: list available plans

    ls --plan plan_name: list contents of the plan with specified name

    add --plan plan_name: add a new plan with specified name

    add --derivedplan plan_name -s/--session session_id -r/--result result_type: derive a plan from the given session

    rm --plan plan_name/all: remove a plan or all plans from repository

    start --plan test_plan_name: run a test plan

    start --plan test_plan_name -d/--device device_ID: run a test plan using the specified device

    start --plan test_plan_name -t/--test test_name: run a specific test

    start --plan test_plan_name -p/--package java_package_name: run a specific java package

    start --plan test_plan_name -t/--test test_name -d/--device device_ID: run a specific test using the specified device

    start --plan test_plan_name -p/--package java_package_name -d/--device device_ID: run a specific java package using the specified device

  Package:

    ls -p/--package: list available packages

    ls -p/--package package_name: list contents of the package with specified name

    add -p/--package root: add packages from root to repository

    rm -p/--package package_name/all: remove a package or all packages from repository

  Result:

     ls -r/--result: list all result of sessions

    ls -r/--result -s/--session session_id: list detail case result of a specified session

    ls -r/--result [pass/fail/notExecuted/timeout] -s/--session session_id: list detail cases of a specified session by the specified result.

  History:

    history/h: list all commands in command history

    history/h count: list the latest count records in command history

    history/h -e num: run the command designated by 'num' in command history

  Device:

    ls -d/--device: list available devices
列出所有的 plan

cts_host > ls --plan  

List of plans (8 in total):

CTS

Signature

AppSecurity

Performance

RefApp

Java

VM

Android


查看某 plan 的内容

cts_host > ls --plan Android

Packages of plan Android (29 in total):

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

android.apidemos.cts

android.accessibilityservice

android.accounts

android.app

android.bluetooth

android.content

android.database

android.dpi

android.dpi2

android.example

android.gesture

android.graphics

android.hardware

android.jni

android.location

android.media

android.net

android.os

android.permission2

android.permission

android.provider

android.speech

android.telephony

android.text

android.util

android.view

android.webkit

android.widget

android.tests.appsecurity


添加一个新的 plan

cts_host > add --plan marvell

[Choose package] SignatureTest: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m] Y

Invalid input. Please chose 'y', 'n', or 'm' (default is 'y')

[Choose package] SignatureTest: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m] y

[Choose package] android.accessibilityservice: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m] y

[Choose package] android.accounts: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m] y

[Choose package] android.apidemos.cts: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m]

[Choose package] android.app: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m] y

。。。。

  [Choose package] android.widget: select[Y], reject[n], or choose suite in it[m]?  [Y/n/m]





cts_host > ls --plan marvell

The following package(s) contained in plan marvell have been removed:

    SignatureTest

Packages of plan marvell (55 in total):

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

android.accessibilityservice

android.accounts

android.apidemos.cts

android.app

。。。

android.widget


删除一个 plan

cts_host > rm --plan marvell


执行一个 plan

cts_host > start --plan Performance

start test plan Performance

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

Test package: android.performance2

android.performance2.cts.AppStartup#testStartup........................................................................................................................................................(timeout)

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



CTS_INFO >>> Max ADB operations reached. Restarting ADB...



CTS_INFO >>> Restarting device ...



CTS_INFO >>> Restart complete.

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

Test package: android.performance3

android.performance3.cts.AppStartup#testStartup..............(pass)

CTS_INFO >>> Max ADB operations reached. Restarting ADB...



CTS_INFO >>> Restarting device ...



CTS_INFO >>> Restart complete.

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

Test package: android.performance4

android.performance4.cts.AppStartup#testStartup.......(pass)



CTS_INFO >>> Max ADB operations reached. Restarting ADB...



CTS_INFO >>> Restarting device ...



CTS_INFO >>> Restart complete.

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

Test package: android.performance5

android.performance5.cts.AppStartup#testStartup........(fail)

junit.framework.AssertionFailedError: App Took too long to startup: 715 650 at android.performance5.cts.AppStartup.testStartup(AppStartup.java:67)

at android.performance5.cts.AppStartup.testStartup(AppStartup.java:67)

at java.lang.reflect.Method.invokeNative(Native Method)

at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)

at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)

at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

at android.performance5.cts.AppStartup.testStartup(AppStartup.java:67)

at java.lang.reflect.Method.invokeNative(Native Method)

at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)

at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)

at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)

at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)

at android.app.ApplicationContext.startActivity(ApplicationContext.java:555)

at android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)

at android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)

at java.lang.reflect.Method.invokeNative(Native Method)

at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)

at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)

at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)



Test summary:   pass=2   fail=2   timeOut=1   notExecuted=0   Total=5

Time: 635.927s


查看有多少个包

cts_host > ls -p

Available packages (56 in total):

android.util

android.hardware

。。。

android.core.tests.luni.net

android.jni

android.core.vm-tests


查看某个包

cts_host > ls -p android.net

Test suites (3 in total):

android.net.cts

android.net.wifi.cts

android.net.http.cts


查看测试结果

cts_host > ls -r

List of all results:

Session        Test result                Start time        End time        Test plan name

        Pass    Fail    Timeout    NotExecuted

1        2    2    1    0        2010.06.01 16:18:03    2010.06.01 16:28:39    Performance

2        1    0    0    0        2010.06.01 16:39:38    2010.06.01 16:41:33    Signature
研究 cts 生成文件

cts 脚本文件位于: ~/mydroid/out/host/linux-x86/bin ,它是一个 100 行不到的脚本,最终执行:

java -Xmx512M

-cp ./../framework/ddmlib.jar:./../framework/junit.jar:./../framework/hosttestlib.jar:./../framework/cts.jar:./cts.jar

-DHOST_CONFIG=./../cts/android-cts/repository/host_config.xml

com.android.cts.TestHost

可见, CTS 的 Java 主 程序为: com.android.cts.TestHost ,同时使用了配置文件: host_config.xml.



两个 cts.jar: ./out/host/linux-x86/cts/android-cts/tools/cts.jar ./out/host/linux-x86/framework/cts.jar 相同。



  cts 使用的目录则为: ~/mydroid/out/host/linux-x86/cts
文件列表 1

songlixin @zjujoe-desktop:~/mydroid/out/host/linux-x86/cts$ tree -L 3

.

├── all_cts_core_files_stamp

├── all_cts_files_stamp

├── android-cts

│    ├── docs

│    ├── repository

│    │    ├── host_config.xml

│    │    ├── log_2010.06.01_16.02.21_. txt

│    │    ├── log_2010.06.01_16.12.22_.txt

│    │    ├── log_2010.06.01_16.38.30_.txt

│    │    ├── log_2010.06.01_16.59.50_.txt

│    │    ├── plans

│    │    ├── results

│    │    └── testcases

│    └── tools

│        ├── cts.jar

│        ├── hosttestlib.jar

│        ├── junit.jar

│        └── startcts

├── android-cts.zip

└── temp

└── description.xml



我们关心的主要是 repository 目录。


文件列表 2

songlixin @zjujoe-desktop:~/mydroid/out/host/linux-x86/cts$ tree android-cts/repository/

android-cts/repository/

├── host_config.xml

├── plans

│    ├── Android.xml

│    ├── AppSecurity.xml

│    ├── CTS.xml

│    ├── Java.xml

│    ├── Performance.xml

│    ├── RefApp.xml

│    ├── Signature.xml

│    └── VM.xml

├── results

│    ├── 2010.06.01_16.18.03

│    │    ├── cts_result.css

│    │    ├── cts_result.xsl

│    │    ├── logo.gif

│    │    ├── newrule-green.png

│    │    └── testResult.xml

│    ├── 2010.06.01_16.18.03.zip

│    ├── 2010.06.01_16.39.38

│    │    ├── cts_result.css

│    │    ├── cts_result.xsl

│    │    ├── logo.gif

│    │    ├── newrule-green.png

│    │    └── testResult.xml

│    ├── 2010.06.01_16.39.38.zip

│    ├── cts_result.css

│    ├── cts_result.xsl

│    ├── logo.gif

│    └── newrule-green.png

└── testcases

    ├── android.core.tests.annotation.apk

    ├── android.core.tests.annotation.xml

    ├── android.core.tests.archive.apk

  。。。。。。。。。。。。。。。。。。

    ├── CtsWidgetTestCases.xml

    ├── SignatureTest.apk

    ├── SignatureTest.xml

    └── TestDeviceSetup.apk



5 directories, 156 files



可见 plans  目录下为以 xml 格式定义的测试方案

     results 目录为 测试结果。

     testcases 目录则为一个个测试用例包

host_config.xml 为配置文件


研究 cts 源文件
从根目录开始

Cts 的 source 包位于 android 根目录下:

songlixin @zjujoe-desktop:~/mydroid/cts$ tree -L 2

.

├── Android.mk

├── tests

│    ├── accessibilityservice

│    ├── AndroidManifest.xml

│    ├── Android.mk

│    ├── ApiDemosReferenceTest

│    ├── appsecurity-tests

│    ├── assets

│    ├── config_demo

│    ├── core

│    ├── ProcessTest

│    ├── res

│    ├── SignatureTest

│    ├── src

│    ├── tests

│    └── vm-tests

└── tools

    ├── Android.mk

    ├── annotation-helper

    ├── cts-reference-app-lib

    ├── dasm

    ├── device-setup

    ├── dex-tools

    ├── dx-tests

    ├── host

    ├── signature-tools

    ├── spec-progress

    ├── test-progress

    ├── test-progress-new

    ├── utils

    └── vm-tests



根目录下的 make file 非常简单:



songlixin @zjujoe-desktop:~/mydroid/cts$ cat Android.mk

include $(call all-subdir-makefiles)



看来主要内容在两个子目录下。


子目录 1 : tools

根目录下的 Android.mk 与其父目录相同。

各子目录代表不同的工具,比如 dasm 编译后的位置是: ./out/host/linux-x86/bin/dasm

这里就不仔细分析这些工具了。
子目录 2 : tests

看一下根目录下的 Android.mk:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := tests

LOCAL_SRC_FILES := $(call all-java-files-under, src)\

              $(call all-java-files-under, core/runner/src)\

              src/android/app/cts/ISecondary.aidl\

              src/android/os/cts/IEmptyService.aidl



LOCAL_JAVA_LIBRARIES := android.test.runner



# Resource unit tests use a private locale and some densities

LOCAL_AAPT_FLAGS = -c xx_YY -c cs -c 32dpi -c 240dpi -c 160dpi



LOCAL_PACKAGE_NAME := CtsTestStubs



include $(BUILD_PACKAGE)



# Build the test APK using its own makefile, and any other CTS-related packages

include $(call all-makefiles-under,$(LOCAL_PATH))



所有 src 及 core/runner/src 下的 java 文件被编译成:

./out/host/linux-x86/cts/android-cts/repository/testcases/CtsTestStubs.apk



剩下的就是很多子目录以及子目录的子目录会被编译成 *.apk



Tests 目录下每个子目录包括一个 test suite.

songlixin @zjujoe-desktop:~/mydroid/cts/tests/tests$ tree -L 1

.

├── accessibilityservice

├── accounts

├── Android.mk

。。。

├── webkit

└── widget



Core 目录下每个子目录包含一个 test suite, 但是他们的代码在其他地方

songlixin @zjujoe-desktop:~/mydroid/cts/tests/core$ tree -L 2

.

├── Android.mk

├── annotation

│    ├── AndroidManifest.xml

│    └── Android.mk

├── archive

│    ├── AndroidManifest.xml

│    └── Android.mk

。。。

├── text

│    ├── AndroidManifest.xml

│    └── Android.mk

├── xml

│    ├── AndroidManifest.xml

│    └── Android.mk

└── xnet

    ├── AndroidManifest.xml

    └── Android.mk



appsecurity-tests/test-apps 目录下每个子目录包括一个 test case. 都特别简单 .



songlixin @zjujoe-desktop:~/mydroid/cts/tests/appsecurity-tests/test-apps$ tree -L 1

.

├── Android.mk

├── AppAccessData

├── AppWithData

├── InstrumentationAppDiffCert

├── PermissionDeclareApp

├── SharedUidInstall

├── SharedUidInstallDiffCert

├── SimpleAppInstall

├── SimpleAppInstallDiffCert

├── TargetInstrumentationApp

└── UsePermissionDiffCert


总结

Cts 其实就是基于 instrumentation test, Test case 有很多类型,不同的实现方式。 对我们来说,需要:

1 )     能够执行现有的 test case

2 )     能够模仿 api demo test case 写一些比较简单的:

可以参考: http://www.netmite.com/ \

android/mydroid/cupcake/development/pdk/docs/instrumentation_testing.html


Android CTS 测试研究之三

作者: 宋立新

Email : zjujoe@yahoo.com


前言

前面都是研究 CTS 面上的东西, 这两天认真学习了一下 Android Instrumentation Test 的相关内容,深切体会到其强大的功能!( UI 控制,生命周期控制,伪环境对象提供等等), 回过头来,我们再来看看 CTS 的细节内容。



和前面的内容区分开,我们从具体测试用例的角度来看。





首先选择文档中经常提起的 apidemo 作为研究对象。
例子一: apidemo
从 test plan 开始研究



~/mydroid/out/host/linux-x86/cts/android-cts/repository/plans$ cat CTS.xml

<?xml version="1.0" encoding="UTF-8"?>

<TestPlan version="1.0">

  <Entry uri="android.apidemos.cts"/>

  <Entry uri="android.accessibilityservice"/>

。。。

  <Entry uri="android.core.vm-tests"/>

  <Entry uri="android.tests.appsecurity"/>

</TestPlan>



可见,某个 test plan 只需要包括一个到具体测试用例的 uri 申明即可。



该 uri 的定义在 test cases 子目录下:



~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ cat ApiDemosReferenceTest.xml

<?xml version="1.0" encoding="UTF-8"?>

<TestPackage AndroidFramework="Android 1.0" apkToTestName="ApiDemos" appNameSpace="android.apidemos.cts" appPackageName="android.apidemos.cts" jarPath="" name="ApiDemosReferenceTest" packageToTest="com.example.android.apis" referenceAppTest="true" runner="android.test.InstrumentationTestRunner" targetBinaryName="" targetNameSpace="" version="1.0">

  <TestSuite name="android">

    <TestSuite name="apidemos">

      <TestSuite name="cts">

        <TestCase name="ApiDemosTest">

          <Test name="testNumberOfItemsInListView"/>

        </TestCase>

      </TestSuite>

    </TestSuite>

  </TestSuite>

</TestPackage>



可见 , CTS 在 Android 的 Instrumentation Test 上又包了一层。该 xml 文件的格式说明没有找到,只能先望文生义了。



照字面理解,它要测试 ApiDemo, 测试的代码是 ApiDemoReferenceTest, 使用的 Test runner 是: android.test.InstrumentationTestRunner. ( 其它的 test runner 还有: android.test.InstrumentationCtsTestRunner, android.test.InstrumentationCoreTestRunner)



该 Test 一共只有一个 test:   testNumberOfItemsInListView



以下是相关文件:

songlixin@zjujoe-desktop:~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ ls -l ApiDemo*

-rw-r--r-- 1 songlixin songlixin 2106161 2010-06-16 09:38 ApiDemos.apk

-rw-r--r-- 1 songlixin songlixin    5526 2010-06-16 09:38 ApiDemosReferenceTest.apk

-rw-r--r-- 1 songlixin songlixin     657 2010-06-16 09:38 ApiDemosReferenceTest.xml



现在看看这些位于 out 目录下的文件是如何生成的。


再看源码树

根据参考,   要在 cts 中添加一个 test package, 必须将其加入: build/core/tasks/cts.mk.



查看一下,果然 , 其中包含:

    ApiDemos \

ApiDemosReferenceTest \



ApiDemos 位于:

~/mydroid/development/samples/ApiDemos$ tree -L 2

.

├── AndroidManifest.xml

├── Android.mk

├── assets

│    ├── fonts

│    └── read_asset.txt

├── _index.html

├── res

│    ├── anim

│    ├── drawable

。。。

│    ├── layout

│    ├── menu

│    ├── raw

│    ├── values

。。。

│    └── xml

├── src

│    └── com

└── tests

    ├── AndroidManifest.xml

    ├── Android.mk

    ├── build.properties

    └── src



其中, make file 中包含 tests tag:

LOCAL_MODULE_TAGS := samples tests



ApiDemosReferenceTest 位于:

~/mydroid/cts/tests/ApiDemosReferenceTest$ tree

.

├── AndroidManifest.xml

├── Android.mk

└── src

    └── android

        └── apidemos

            └── cts

                ├── AllTests.java

                └── ApiDemosTest.java



其 make file  没有包含 tests tag, 但是父目录的 Android.mk 中包含了。并且它使用所有子目录的源码。
两个疑问

1)   ApiDemosReferenceTest.xml 是从哪里来的?

猜测: 从 /mydroid/cts/tests/ApiDemosReferenceTest 生成

2)   ApiDemosReferenceTest 中提供了两个 testcase, 而 ApiDemosReferenceTest.xml 只用了一个?



从代码上看, ~/mydroid/cts/tools/utilsbuildCts.py  是用来生成 test description 以及 test plan 的。它在 ~/mydroid/build/core/tasks/cts.mk 中被调用。


例子二: CtsExample

CTS test plan 中有:

<Entry uri="android.example"/>



这对应:

~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ ls -l CtsExampleTestCases.*

-rw-r--r-- 1 songlixin songlixin 3294 2010-06-16 10:58 CtsExampleTestCases.apk

-rw-r--r-- 1 songlixin songlixin 1257 2010-06-16 10:59 CtsExampleTestCases.xml



看它的 xml 文件:

<?xml version="1.0" encoding="UTF-8"?><TestPackage AndroidFramework="Android 1.0" appNameSpace="com.android.cts.example" appPackageName="android.example " name="CtsExampleTestCases" runner="android.test.InstrumentationTestRunner" version="1.0">

    <TestSuite name="android">

        <TestSuite name="example">

            <TestSuite name="cts">

                 <TestCase name="ExampleTest">

                    <Test name="testBlort">

                        <Description>                            Test {@link Example#blort}.                        </Description>

                    </Test>

                 </TestCase>

                <TestCase name="ExampleSecondaryTest">

                    <Test name="testZorch">

                        <Description>                            Test {@link Example#zorch}.                        </Description>

                     </Test>

                </TestCase>

            </TestSuite>

        </TestSuite>

    </TestSuite>

</TestPackage>



其中包含了两个 test case.



我们再看 build/core/tasks/cts.mk :

CtsExampleTestCases \



该 package 位于:

~/mydroid/cts/tests/tests/example$ tree

.

├── AndroidManifest.xml

├── Android.mk

└── src

    └── android

        └── example

            ├── cts

            │    ├── ExampleSecondaryTest.java

            │    └── ExampleTest.java

            └── Example.java



该 package 的特殊之处在于它的测试代码以及被测试代码都在同一个包内。

两个 TestCase 都是从 TestCase 继承,因为它不需要更复杂的功能。



可以发现, 相比较 ApiDemo 而言,这是一个更典型的 CTS 测试的例子。如果您想写自己的 cts 测试用例,不凡模仿它。更进一步说, cts/tes/tests 下的那些例子更适合我们用来参考。比如: performance 目录下的 MultiAppStartupTest, 继承了 InstrumentationTestCase. 也是一个很好的例子。



另外,还发现每个例子其包的最后一段总是 cts, 不知是不是硬性要求。这也可以说明 CTS 是基于 instrumentation test, 但是又不等同。

疑问

AndroidManifest.xml 中定义的 package name 为: com.andoid.cts.example



Example 类属于:

package android.example;

public class Example



ExampleTest 类属于:

package android.example.cts;

public class ExampleTest extends TestCase

非常奇怪!




单个运行 CTS 测试用例
安装

~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ adb install CtsPerformanceTestCases.apk

70 KB/s (4518 bytes in 0.062s)

       pkg: /data/local/tmp/CtsPerformanceTestCases.apk

Success



查看一下已经安装的 instrumentation

~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ adb shell pm list instrumentation

instrumentation:com.android.cts.performance/android.test.InstrumentationTestRunner (target=com.android.calculator2)

instrumentation:com.android.example.spinner.test/android.test.InstrumentationTestRunner (target=com.android.example.spinner)

instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)

instrumentation:com.example.helloandroid.test/android.test.InstrumentationTestRunner (target=com.example.helloandroid)


运行(失败)

:~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$ adb shell am instrument -w -r com.android.cts.performance/android.test.InstrumentationTestRunner

INSTRUMENTATION_STATUS: id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS: class=android.performance.cts.MultiAppStartupTest

INSTRUMENTATION_STATUS: stream=

android.performance.cts.MultiAppStartupTest:

INSTRUMENTATION_STATUS: numtests=1

INSTRUMENTATION_STATUS: test=testMultipleApps

INSTRUMENTATION_STATUS_CODE: 1

INSTRUMENTATION_STATUS: id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS: class=android.performance.cts.MultiAppStartupTest

INSTRUMENTATION_STATUS: stream=

Error in testMultipleApps:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.calendar/com.android.calendar.LaunchActivity}; have you declared this activity in your AndroidManifest.xml?

       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)

       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)

       at android.app.ApplicationContext.startActivity(ApplicationContext.java:555)

       at android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)

       at android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)

       at java.lang.reflect.Method.invokeNative(Native Method)

       at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)

       at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)

       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

       at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)

       at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)



INSTRUMENTATION_STATUS: numtests=1

INSTRUMENTATION_STATUS: stack=android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.calendar/com.android.calendar.LaunchActivity}; have you declared this activity in your AndroidManifest.xml?

       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)

       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)

       at android.app.ApplicationContext.startActivity(ApplicationContext.java:555)

       at android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)

       at android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)

       at java.lang.reflect.Method.invokeNative(Native Method)

       at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)

       at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)

       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

       at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

       at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)

       at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)



INSTRUMENTATION_STATUS: test=testMultipleApps

INSTRUMENTATION_STATUS_CODE: -1

INSTRUMENTATION_RESULT: stream=

Test results for InstrumentationTestRunner=.E

Time: 6.729



FAILURES!!!

Tests run: 1,  Failures: 0,  Errors: 1





INSTRUMENTATION_CODE: -1

songlixin@zjujoe-desktop:~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$
修改

出错信息说是找不到:calendar



修改代码,使其不启动 calendar:

        //launchActivity("com.android.calendar", "LaunchActivity", true);

        //Thread.sleep(ACTIVITY_STARTUP_WAIT_TIME);



重新编译: make cts


重新安装

重新安装用:adb install -r CtsPerformanceTestCases.apk


运行(成功)

~/mydroid/out/host/linux-x86/cts/android-cts/repository/testcases$

adb shell am instrument -w -r com.android.cts.performance/android.test.InstrumentationTestRunner

INSTRUMENTATION_STATUS: id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS: class=android.performance.cts.MultiAppStartupTest

INSTRUMENTATION_STATUS: stream=

android.performance.cts.MultiAppStartupTest:

INSTRUMENTATION_STATUS: numtests=1

INSTRUMENTATION_STATUS: test=testMultipleApps

INSTRUMENTATION_STATUS_CODE: 1

INSTRUMENTATION_STATUS: id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS: class=android.performance.cts.MultiAppStartupTest

INSTRUMENTATION_STATUS: stream=.

INSTRUMENTATION_STATUS: numtests=1

INSTRUMENTATION_STATUS: test=testMultipleApps

INSTRUMENTATION_STATUS_CODE: 0

INSTRUMENTATION_RESULT: stream=

Test results for InstrumentationTestRunner=.

Time: 7.389



OK (1 test)


总结

至此,我们大体知道如何运行 cts, 配置 cts, 扩充 cts, 下一步就看具体实践了!

参考链接里有如何添加一个 cts 测试、修改 test plan 的信息,所以本文就没有重复。
参考

Android CTS (Compatibility Test Suite) introduction

http://androidboss.com/android-c ... ite-introduction-2/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值