[Android test] use the command line tool for testing

Source: Internet
Author: User

Address: https://developer.android.com/tools/testing/testing_otheride.html

This chapter mainly describes how to use the command line to create the Dynamic Route Project, the dynamic route creation class, the operation class, And the instrumentation command.

Project

The method for creating a new deployment project is as follows:

Android create test-project-M <main_path>-n <project_name>-P <test_path>

The following describes the number of arguments involved in the preceding command line.

Flag

Value

Description

-M or -- Main

Targeted route chart (view the contents of the package)

Example: If the destination path is source/helloandroid, then this parameter should be followed./helloandroid

-N or -- name

Target name

Example: If the target name is helloandroid, we can define helloandroidtest

-P or -- path

The destination object of the stored items.

Stores the files and contents generated by the android tool.

Example:

Parker @ Parker :~ $ CD/data/workplace/

Parker @ Parker:/data/workplace $ Android create test-project-M ../helloandroid-N helloandroidtest-P helloandroidtest

Update the zookeeper Project

If you have already created an engineering project, but we want to change it now, we can use:

Android update test-project-M <main_path>-P <test_path>

Zookeeper

Although your test package can be combined with activity, Android test extension class, JUnit extension or common class, but you should inherit Android test class or JUnit class because they provide the best test function.

If you run your test through instrumentationtestrunner (or related test runner), it will run all the test methods in each class. You can change these behaviors by using the testsuit class.

The strongswan package contains the entation class and some classes that inherit testcase. These methods may overwrite the setup () and teardown () methods. Setup () is mainly used to set the test environment. You can initialize an intent object here and use intent to enable the test activity. Teardown () is called after all tests are completed. It recycles and resets garbage before moving to the next group of tests.

In general, we often add the testpreconditions () method to the test class. This method is used to initialize the test application correctly. If the test fails, you know an error occurs during initialization. In this case, the results of further tests are questionable unless you do not care whether the test is successful or not.

Running Condition

1. We can use ant to quickly compile and run Android scripts. We can use ant to run dynamic route for all dynamic route entries.

2. We can also run the program in the module runner and real-world settings. First, the application and zookeeper projects of the zookeeper must be merged to the configuration engineer, and then the am command in the ADB shell should be used.

$ ADB shell am instrument-W <test_package_name>/<runner_class>

<Test_package_name> is the name of the target package for zookeeper, and <runner_class> is the name of the android test runner, which is generally consistent with the name in the <instrumentation> object in androidmanifest.

The following describes the number of arguments involved in the preceding command line.

Flag

Value

Description

-W

None

Keep the ADB shell open until the test is complete.

-R

None

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

-E

<Test_operation>

Provides test options in the form of key-value pairs. Android provides a variety of key-value pairs, detailed information can view their own http://developer.android.com/tools/testing/testing_otheride.html#AMSyntax

Example:

Root @ Android:/# Am instrument-w aexp. JUnit. Test/Android. Test. instrumentationtestrunner

AEXP. JUnit. contacttest :...

AEXP. JUnit. mathtest :..

Test results for instrumentationtestrunner = .....

Time: 0.204

OK (5 tests)

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.