How to add a test plan, package to Android CTS? --Erin Yueh

上一篇 / 下一篇  2011-12-07 09:34:26 / 个人分类:

 If we check Android source code, we can find some test packages in Android applications. We can either run these test packages in Android device or we can combine them with Android CTS from host machine. Here is an example from Music application. I will create a test planMusicTestsand test packageMusicTestCasesin CTS.

Add test package source code to cts folder


$ cp -a $MYDROID/packages/apps/Music/tests $MYDROID/cts/tests/tests/MusicTests



Modify test package name in Android.mk to avoid redundant name

$ cat $MYDROID/cts/tests/tests/MusicTests/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
# We only want this apk build for tests.
LOCAL_MODULE_TAGS := tests

LOCAL_JAVA_LIBRARIES := android.test.runner

# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := MusicTestsCases

LOCAL_INSTRUMENTATION_FOR := Music

include $(BUILD_PACKAGE)



Add one test case to CTS_CASE_LIST in build/core/tasks/cts.mk

erin@midnight:~/eclair/build/core$ git diff
diff --git a/core/tasks/cts.mk b/core/tasks/cts.mk
index 917c5dc..17f6dbc 100644
--- a/core/tasks/cts.mk
+++ b/core/tasks/cts.mk
@@ -97,6 +97,7 @@ CTS_CASE_LIST := /
       CtsPerformance3TestCases /       CtsPerformance4TestCases /       CtsPerformance5TestCases / +      MusicTestsCases /
       ApiDemos /       ApiDemosReferenceTest /       $(CTS_CORE_CASE_LIST) /



Add test plan 'MusicTests' in cts/tools/utils/buildCts.py

def GenerateTestPlans(self):   .....   plan = tools.TestPlan(packages)   plan.Include(r'android/.MusicTests')   self.__WritePlan(plan, 'MusicTests')



make cts again


$ cd $MYDROID
$ . build/envsetup.sh
$ make cts


run MusicTestCases

$ cd $mydroid/out/host/linux-x86/bin/
$ ./cts

cts_host > start --plan MusicTests
start test plan MusicTests
==============================================================
Test package: android.MusicTests
install met failure [install_failed_insufficient_storage]
com.android.music.tests.stress.AlbumsPlaybackStress#testAlbumPlay.....(pass)
com.android.music.tests.stress.AlbumsPlaybackStress#testActivityTestCaseSetUpProperly....(pass)
com.android.music.tests.stress.MusicPlaybackStress#testPlayAllSongs....(pass)
com.android.music.tests.stress.MusicPlaybackStress#testActivityTestCaseSetUpProperly....(pass)
com.android.music.tests.functional.TestPlaylist#testDeletePlaylist....(pass)
com.android.music.tests.functional.TestPlaylist#testRenamePlaylist....(pass)
com.android.music.tests.functional.TestPlaylist#testActivityTestCaseSetUpProperly....(pass)
com.android.music.tests.functional.TestSongs#testAddPlaylist.....(pass)
com.android.music.tests.functional.TestSongs#testSetRingtone.....(pass)
com.android.music.tests.functional.TestSongs#testDeleteSong.....(pass)
com.android.music.tests.functional.TestSongs#testActivityTestCaseSetUpProperly....(pass)
com.android.music.tests.MusicPlayerStability#testPlay30sMP3....(pass)
com.android.music.tests.MusicPlayerStability#testLaunchMusicPlayer....(pass)
==============================================================
Test summary: pass=13 fail=0 timeOut=0 notExecuted=0 Total=13
Time: 100.780s


TAG:

haldis的个人空间 引用 删除 haldis   /   2011-12-07 10:01:46
How to add test plan, test packages to CTS?
Add test package name to cts.mk, it would generate apk file when we build cts.
Add all source folder (includes src java files, Android.mk and its Manifest file) to mydroid/cts/tests/tests
If you'd like to create a test plan for this test package. Modify this python script: mydroid/cts/tools/utils/buildCts.py

Adjust CTS program settings?

Modify $mydroid/cts/tools/utils/host_config.xml

Number of tests executed between reboots. A value <= 0 disables reboots. (maxTestCount)
Max size [tests] for a package to be run in batch mode. (maxTestInBatchMode)
Max time [ms] between test status updates. (testStatusTimeoutMs)
Max time [ms] from start of package in batch mode and the first test status update. (batchStartTimeoutMs)
Max time [ms] from start of test in individual mode to the first test status update. (individualStartTimeoutMs)
Timeout [ms] for the signature check. (signatureTestTimeoutMs)
Timeout [ms] for package installations. (packageInstallTimeoutMs)
Time to wait [ms] after a package installation or removal. (postInstallWaitMs)
Write your own testing package?

If you would like to write your own testing package, you may reference the Instrumentation Testing document from Android porting guide. Also, you could reference the source code from few Android application, like Browser, Messages, Gallery, Email, Camera, Calculator....etc. You can build its test apk file and upload it to device.

How to write test cases?
Each instrumentation test case is similar to an Android application with the distinction that it starts another application. For example, have a look in the $MYDROID/packages/apps/Music directory.

There should be a Makefile and an Android Manifest file
Tests are located in $MYDROID/packages/apps/Music/tests.
The Instrumentation Test Runner is located at packages/apps/Music/tests/src/com/android/music/MusicPlayerFunctionalTestRunner.java.

Build package apk file

erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ mm
Install: out/target/product/generic/data/app/MusicTests.apk

Install it to the device
erin@midnight:~/eclair/mydroid/packages/apps/Music/tests$ adb install ../../../../out/target/product/generic/data/app/MusicTests.apk

How to run test cases in device?

Running Tests


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)


The am command is a command-line interface to the ActivityManager. 'am' is used to start and instrument activities using the adb shell command, as shown in the snippet below:

> adb shell amusage: am [start|instrument]       am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]                [-c <CATEGORY> [-c <CATEGORY>] ...]                [-e <EXTRA_KEY> <EXTRA_VALUE> [-e <EXTRA_KEY> <EXTRA_VALUE> ...]                [-n <COMPONENT>] [-D] [<URI>]       am instrument [-e <ARG_NAME> <ARG_VALUE>] [-p <ROF_FILE>]                [-w] <COMPONENT> For example, to start the Contacts application you can use> adb shell am start -n com.google.android.contacts/.ContactsActivity

Eg. verify Music player launcher performance


erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerLaunchPerformance


Eg. verify Music player stress test


erin@midnight:~/$ adb shell am instrument -w -r com.android.music.tests/.MusicPlayerStressTestRunner


Here is a video about running a cts test case by Android emulator!
 

评分:0

我来说两句

Open Toolbar