Android basics 12: Android automated testing 06-Instrumentation 06 ADB shell AM

Source: Internet
Author: User

[ADB shell am instrument]
Note: The-e option must be placed before the-W option.
-W <test_package_name>/<runner_class> (<test_package_name> and <runner_class> search for them in androidmanifest. xml of the test project)
Purpose: Keep the ADB shell open until the test is complete.
Example:-W com. Android. Phone. Tests/COM. Android. Phone. Runners. functionaltestrunner
-E <key> <value>
Purpose: Provides test options in the form of key-value pairs. Android provides multiple key-value pairs. For more information, see the following table.
Example:-E Class com. Android. Phone. fincomingcalltests # testrejectcall (value is a fully qualified class name)
-R

Purpose: output the test results in the original form. This option is usually used with-e perf true during performance testing.

<Key> <value> reference table

Typical usage
  1. WriteTestCaseS 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 (benchmark t 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 bothLargeTest
And "com. Android. Foo. myannotation" annotations.

Filter test run to testsWithoutGiven 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.

After verification, it seems that you cannot run all the small and medium cases at a time.-E size can only specify one label. For the smoke tag, the-e annotation Android. Test. suitebuilder. annotation. Smoke command is required.

[ADB shell am start]
-N <package_name>/. <activity_class_name>
Purpose: Start an activity.
Example: ADB shell am start-N com. Lt. AM/. myamactivity

[ADB shell am startservice]
-N <package_name>/. <service_class_name>
Purpose: Start a service
Example: ADB shell am startservice-N com. Lt. AM/. myamservice

[ADB shell AM broadcast]
-A <action_name>
Purpose: Send a broadcast.
Example: ADB shell AM broadcast-a "action_finish" (send a broadcast to close an activity)
Purpose: Restore the factory settings to clear all content in the memory.
Example: ADB shell AM broadcast-A Android. Intent. Action. master_clear

Reference: Android-sdks \ docs \ tools \ Testing \ testing_otheride.html

References:

Use of ADB shell AM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.