【前言】CTS 测试某个testcase常用的测试方法:CTS tool or atest都可以满足,选哪个使用要结合当前开发测试环境,这里简单介绍另一种方法:instrumentation,详细介绍参考:https://source.android.google.cn/compatibility/tests/development/instrumentation
【使用】
- adb install “cts apk“,比如CtsMediaV2TestCases apk
- adb?shell pm list instrumentation,列出来的结果填在下面-w的后面
instrumentation:android.mediav2.cts/androidx.test.runner.AndroidJUnitRunner (target=android.mediav2.cts) - adb shell am instrument? -r -e class "class_name#method_name" -w "instrumentation",instrumentation在测试apk的AndroidManifest.xml里有声明。
adb shell am instrument? -e class "class_name#method_name" -r -w "instrumentation"? =>测试某个case
adb shell am instrument? -e class "class_name" -r -w "instrumentation"? =>测试某个class
adb shell am instrument? -w "instrumentation"? =>测试整个module
如下测试:
adb shell am instrument -r -e class android.mediav2.cts.CodecDecoderPauseTest -w android.mediav2.cts/androidx.test.runner.AndroidJUnitRunner
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
android.mediav2.cts.CodecDecoderPauseTest:
INSTRUMENTATION_STATUS: test=testPause[0(c2.android.aac.decoder_audio/mp4a-latm)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[0(c2.android.aac.decoder_audio/mp4a-latm)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[1(OMX.realtek.video.decoder_video/3gpp)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=2
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[1(OMX.realtek.video.decoder_video/3gpp)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=3
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[2(c2.android.h263.decoder_video/3gpp)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=3
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[2(c2.android.h263.decoder_video/3gpp)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=4
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[3(OMX.realtek.video.decoder_video/avc)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=4
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[3(OMX.realtek.video.decoder_video/avc)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=5
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[4(c2.android.avc.decoder_video/avc)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=5
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[4(c2.android.avc.decoder_video/avc)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=6
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[5(OMX.realtek.video.decoder_video/hevc)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=6
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[5(OMX.realtek.video.decoder_video/hevc)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=7
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[6(c2.android.hevc.decoder_video/hevc)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=7
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[6(c2.android.hevc.decoder_video/hevc)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=8
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[7(OMX.realtek.video.decoder_video/mp4v-es)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=8
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[7(OMX.realtek.video.decoder_video/mp4v-es)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=9
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[8(c2.android.mpeg4.decoder_video/mp4v-es)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=9
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[8(c2.android.mpeg4.decoder_video/mp4v-es)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=10
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[9(OMX.realtek.video.decoder_video/mpeg2)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=10
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[9(OMX.realtek.video.decoder_video/mpeg2)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=11
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[10(c2.android.mpeg2.decoder_video/mpeg2)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=11
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[10(c2.android.mpeg2.decoder_video/mpeg2)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=12
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[11(OMX.realtek.video.decoder_video/x-vnd.on2.vp9)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=12
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[11(OMX.realtek.video.decoder_video/x-vnd.on2.vp9)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=13
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[12(c2.android.vp9.decoder_video/x-vnd.on2.vp9)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=13
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[12(c2.android.vp9.decoder_video/x-vnd.on2.vp9)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=14
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=
INSTRUMENTATION_STATUS: test=testPause[13(c2.android.vp8.decoder_video/x-vnd.on2.vp8)]
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: class=android.mediav2.cts.CodecDecoderPauseTest
INSTRUMENTATION_STATUS: current=14
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: numtests=14
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: test=testPause[13(c2.android.vp8.decoder_video/x-vnd.on2.vp8)]
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_RESULT: stream=
Time: 153.618
OK (14 tests)
INSTRUMENTATION_CODE: -1
【other】
? am instrument参数:
命令格式:
instrument [-r] [-e ] [-p ] [-w] [--user | current] [--no-window-animation] [--abi ]
Start an Instrumentation. Typically this target is in the form / or only if there is only one instrumentation.
Options are:
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with [-e perf true] to generate raw output for performance measurements.
-e : set argument to . For test runners a common form is [-e [,...]].
-p : write profiling data to
-m: Write output as protobuf (machine readable)
-w: wait for instrumentation to finish before returning. Required for test runners.
--user | current: Specify user instrumentation runs in; current user if not specified.
--no-window-animation: turn off window animations while running.
--abi : Launch the instrumented process with the selected ABI. This assumes that the process supports the selected ABI
各项参数:
-r:以原始形式输出测试结果;该选项通常是在性能测试时与[-e perf true]一起使用。
-e name value:提供了以键值对形式存在的过滤器和参数。例如:-e testFile (运行文件中指定的用例);-e package (运行这个包中的所有用例)…… 有十几种。
-p file:将分析数据写入file。
-w:测试运行器需要使用此选项。-w / :和在测试工程的AndroidManifest.xml中查找,作用是保持adb shell打开直至测试完成。
--no-window-animation:运行时关闭窗口动画。
--useruser_id | current:指定仪器在哪个用户中运行;如果未指定,则在当前用户中运行。
参考:
1、https://www.freesion.com/article/6158235376/
2、使用Instrumentation命令测试cts apk - 简书
|