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 plan MusicTests and test package MusicTestCases in 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
(Original: http://i-miss-erin.blogspot.com/2010/05/how-to-add-test-plan-package-to-android.html)