android基礎知識12:android自動化測試06—Instrumentation 06 adb shell am

來源:互聯網
上載者:User

[adb shell am instrument]
注意:-e選項需要放在-w選項之前
-w <test_package_name>/<runner_class>  (<test_package_name>和<runner_class>在測試工程的AndroidManifest.xml中尋找)
作用:保持adb shell開啟直至測試完成
舉例:-w com.android.phone.tests/com.android.phone.runners.FunctionalTestRunner
-e <key> <value>
作用:提供了以索引值對形式存在的測試選項。Android中提供了多種索引值對,具體參見下表。
舉例:-e class com.android.phone.FIncomingCallTests#testRejectCall (value為完整類名)
-r

作用:以原始形式輸出測試結果。該選項通常是在效能測試時與-e perf true一起使用。

<key> <value>參考表

Typical Usage
  1. Write TestCases that perform unit, functional, or performance tests against the classes in your package. Typically these are subclassed
    from:

    • ActivityInstrumentationTestCase2
    • ActivityUnitTestCase
    • AndroidTestCase
    • ApplicationTestCase
    • InstrumentationTestCase
    • ProviderTestCase
    • ServiceTestCase
    • SingleLaunchActivityTestCase
  2. In an appropriate AndroidManifest.xml, define the this instrumentation with the appropriate android:targetPackage set.
  3. Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests).
  4. Run the instrumentation using "adb shell am instrument -w", with the argument '-e func true' to run all functional tests. These are tests that derive fromInstrumentationTestCase.
  5. Run the instrumentation using "adb shell am instrument -w", with the argument '-e unit true' to run all unit tests. These are tests thatdo notderive fromInstrumentationTestCase
    (and are not performance tests).
  6. Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individualTestCase.

Running all tests: adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner

Running all small tests: adb shell am instrument -w -e size small com.android.foo/android.test.InstrumentationTestRunner

Running all medium tests: adb shell am instrument -w -e size medium com.android.foo/android.test.InstrumentationTestRunner

Running all large tests: adb shell am instrument -w -e size large com.android.foo/android.test.InstrumentationTestRunner

Filter test run to tests with given annotation: adb shell am instrument -w -e annotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner

If used with other options, the resulting test run will contain the union of the two options. e.g. "-e size large -e annotation com.android.foo.MyAnnotation" will run only tests with both theLargeTest
and "com.android.foo.MyAnnotation" annotations.

Filter test run to tests without given annotation: adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner

Running a single testcase: adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/android.test.InstrumentationTestRunner

Running a single test: adb shell am instrument -w -e class com.android.foo.FooTest#testFoo com.android.foo/android.test.InstrumentationTestRunner

Running multiple tests: adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner

Running all tests in a java package: adb shell am instrument -w -e package com.android.foo.subpkg com.android.foo/android.test.InstrumentationTestRunner

Including performance tests: adb shell am instrument -w -e perf true com.android.foo/android.test.InstrumentationTestRunner

To debug your tests, set a break point in your code and pass: -e debug true

To run in 'log only' mode -e log true This option will load and iterate through all test classes and methods, but will bypass actual test execution. Useful for quickly obtaining info on the tests to be executed by an instrumentation command.

To generate EMMA code coverage: -e coverage true Note: this requires an emma instrumented build. By default, the code coverage results file will be saved in a /data//coverage.ec file, unless overridden by coverageFile flag (see below)

To specify EMMA code coverage results file path: -e coverageFile /sdcard/myFile.ec
in addition to the other arguments.

    經過驗證,貌似無法一次運行所有的small和medium 的case,-e size 只能指定一種標籤。對於smoke標籤,貌似需要使用 -e annotation android.test.suitebuilder.annotation.Smoke命令。

[adb shell am start]
-n <package_name>/.<activity_class_name>
作用:啟動一個activity
舉例:adb shell am start -n com.lt.am/.MyAMActivity

[adb shell am startservice]
-n <package_name>/.<service_class_name>
作用:啟動一個service
舉例:adb shell am startservice -n com.lt.am/.MyAMService

[adb shell am broadcast]
-a <action_name>
作用:發送一個廣播
舉例:adb shell am broadcast -a "action_finish" (發送一個廣播去關閉一個activity)
作用:恢復出廠預設值的方法,會清除記憶體所有內容
舉例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR 

參考文檔:android-sdks\docs\tools\testing\testing_otheride.html

參考資料:

《adb shell am的使用》

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.