Android CTS (Compatibility Test Suite) introduction
http://i-miss-erin.blogspot.com/2010/04/android-cts-compatibility-test-suite.html
なんだ、こんな記事あるんじゃん...
からっぽだったのが、今は埋まっているのね。
http://d.hatena.ne.jp/kinneko/20100112/p5
CTSとは何か?
互換性テストスーツ(CTS)は、コマンドラインで動作する、Androidで一連のテストケースを動作させるためのソフトウエアです。それらは、すべて2010年1月にリリースされたEclairブランチに含まれて公開されました。
gitリポジトリ
http://android.git.kernel.org/?p=platform/cts.git;a=summary
ホストマシンでCTSを走らせる方法
$ cd $MYDROID
$ . build/envsetup.sh
$ make cts
(全てのテストプラン、パッケージ、ケース、結果報告書などはまとめて、android-cts.zipファイルにアーカイブされます)
・CTSパッケージ: out/host/linux-x86/cts/android-cts.zip
・CTS make ファイル: mydroid/build/core/tasks/cts.mk
・CTSの実行: mydroid/out/host/linux-x86/bin/cts
・テストプラン: mydroid/out/host/linux-x86/cts/android-cts/repository/plans
・テストパッケージ: mydroid/out/host/linux-x86/cts/android-cts/repository/testcases
・テスト結果: mydroid/out/host/linux-x86/cts/android-cts/repository/results
・CTS設定項目: mydroid/cts/tools/utils/host_config.xml
CTSを走らせる。
画面には以下のように表示されます:
erin@midnight:~/eclair/mydroid/out/host/linux-x86/bin$ ./cts Android CTS version 2.1_r1 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
CTSにテスト計画、テストパッケージを追加するには
1. テストするパッケージ名をcts.mkに追加すると、CTSをビルドする時にapkファイルを生成します。
2. すべてのソースフォルダ(javaソースファイル、Android.mk、そのManifestファイルを含む)をmydroid/cts/tests/testsに追加します。
3. このテストパッケージについてのテスト計画を作るのであれば、以下のPythonスクリプトを修正します:mydroid/cts/tools/utils/buildCts.py
CTS設定を調整する
$mydroid/cts/tools/utils/host_config.xmlを修正します。
・maxTestCount:再起動までの間に何回実行するか。0の場合は再起動を行いません
・maxTestInBatchMode:バッチモードで動作するパッケージの最大サイズ
・testStatusTimeoutMs:テストステイタスをアップデートする最大時間(ms)
・batchStartTimeoutMs:バッチモードのテスト開始から最初にステイタスアップデートが起きるまでの最大時間(ms)
・individualStartTimeoutMs:不可視モードテストの開始から最初にステイタスアップデートが起きるまでの最大時間(ms)
・signatureTestTimeoutMs:電子署名確認のタイムアウト時間(ms)
・packageInstallTimeoutMs:パッケージインストール時のタイムアウト時間(ms)
・postInstallWaitMs:パッケージのインストール、アンインストール後の待ち時間(ms)
独自のパッケージのテストを記述するには
独自のテストパッケージを書くには、Androidポーティングガイドに含まれている"Instrumentation Testing document (http://www.netmite.com/android/mydroid/development/pdk/docs/instrumentation_framework.html)"を参照してください。また、ブラウザ、メッセージ、ギャラリー、メール、カメラ、電卓など、いくつかのAndroidアプリケーションのソースコードを参考にすることができます。それらのテスト用apkファイルをビルドして、実機に転送して動作させてみるることができます。
テストケースの書き方
それぞれのテストケースの実装は、Androidアプリケーションが異なるアプリケーションから起動される場合と似ています。例えば、$MYDROID/packages/apps/Musicを見てみましょう。
・MakefileとAndroid Manifestファイルが必要です
・テストは、以下に置かれます:$MYDROID/packages/apps/Music/tests
・Instrumentation Test Runnerは、以下に置かれます:$packages/apps/Music/tests/src/com/android/music/MusicPlayerFunctionalTestRunner.java
apkファイルをビルドする
erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ mm Install: out/target/product/generic/data/app/MusicTests.apk
デバイスにインストールする
erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ adb install ../../../../out/target/product/generic/data/app/MusicTests.apk
デバイスでテストケースを動作させる
テストを走らせる。
erin@midnight:~/$ adb shell pm list instrumentation instrumentation:com.android.music.tests/.MusicPlayerStressTestRunner (target=com.android.music) instrumentation:com.android.music.tests/.MusicPlayerFunctionalTestRunner (target=com.android.music) instrumentation:com.android.music.tests/.MusicPlayerLaunchPerformance (target=com.android.music)
amコマンドは、ActivityManagerのコマンドライン・インターフェイスです。"am"コマンドは、以下に示すように、adbシェルコマンドを使って、アプリケーションを開始し、アクティビティを与えます。:
> adb shell am
usage: am [start|instrument]
am start [-a] [-d ] [-t ]
[-c[-c ] ...]
[-e[-e ...]
[-n] [-D] [ ]
am instrument [-e] [-p ]
[-w]For example, to start the Contacts application you can use
> adb shell am start -n com.google.android.contacts/.ContactsActivity
例)音楽プレーヤーの起動速度を確認する
erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerLaunchPerformance
例) 音楽プレーヤーにストレステストを実行する
erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerStressTestRunner
AndroidエミュレータでCTSを動作させた様子は、以下の動画で確認できます。