如何siri通过了图灵测试么Android CTS测试

转宋立新大牛的博客
Android CTS 测试研究
Android CTS 测试研究
从各种渠道了解到 Android CTS 测试, 是一种类似于 Windows Mobile LTK 的测试。
一下, 发现关于 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
性能: 启动
MMS/SMS & 700ms
AlarmClock & 650ms
第二次启动一个应用的时间不能超过第一次启动时间。
CTS 测试: 必须通过最新的 CTS
升级: 必须有一种
可以升级全
。 可以为:
看来 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
进入 cts 交互环境, 可以敲入 help 看各种命令:cts_host & help
这里是quick start,所以不详解。
7) 在 shell 下直接以非交互模式运行一下:
$ cts start --plan Signature
该测试用例比较少,发现两分钟可以运行通过。 像 Android 测试方案就比较耗时间了。
1. 某大牛的 Blog 文章
/blog/44/using-
s-compatibility-test-suite
2. Android
/compatibility/downloads.html
Android CTS 测试研究之二
作者: 宋立新
继续较深入了解 CTS 的细节
先研究一下具体用法
命令行下敲 cts 进入命令行 ,
先看一下帮助
cts_host & help
Usage: command options
Avaiable commands and options:
& & help: show this message
& & exit: exit cts command line
& & 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
&&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
& &&&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
&&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
& & ls -d/--device: list available devices
列出所有的 plan
cts_host & ls --plan&&
List of plans (8 in total):
AppSecurity
Performance
查看某 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
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
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)
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
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)
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
android.app.ApplicationContext.startActivity(ApplicationContext.java:555)
android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)
android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)
at java.lang.reflect.Method.invokeNative(Native Method)
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
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.
Android CTS 测试研究之三
作者: 宋立新
前面都是研究 CTS 面上的东西, 这两天认真学习了一下 Android Instrumentation Test
的相关内容,深切体会到其强大的
控制,生命周期控制,伪环境对象提供等等), 回过头来,我们再来看看 CTS 的细节内容。
和前面的内容区分开,我们从具体测试用例的角度来看。
首先选择文档中经常提起的 apidemo 作为研究对象。
例子一: apidemo
从 test plan 开始研究
~/mydroid/out/host/linux-x86/cts/android-cts/repository/plans$ cat
&?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 0-06-16 09:38 ApiDemos.apk
-rw-r--r-- 1 songlixin songlixin& & -16 09:38
ApiDemosReferenceTest.apk
-rw-r--r-- 1 songlixin songlixin& &&&657
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 -16 10:58
CtsExampleTestCases.apk
-rw-r--r-- 1 songlixin songlixin -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.
public class Example
ExampleTest 类属于:
package android.example.
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
查看一下已经安装的 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?
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
android.app.ApplicationContext.startActivity(ApplicationContext.java:555)
android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)
android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)
& && & at java.lang.reflect.Method.invokeNative(Native Method)
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
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?
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
android.app.ApplicationContext.startActivity(ApplicationContext.java:555)
android.performance.cts.MultiAppStartupTest.launchActivity(MultiAppStartupTest.java:52)
android.performance.cts.MultiAppStartupTest.testMultipleApps(MultiAppStartupTest.java:89)
& && & at java.lang.reflect.Method.invokeNative(Native Method)
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
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&,
& && &&&//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
/android-c ...
ite-introduction-2/
阅读(...) 评论()

我要回帖

更多关于 商品未通过测试阶段 的文章

 

随机推荐