命令行启动应用的几种常见类型

转自:http://www.robotium.cn/archives/799
 
am instrument [flags] <COMPONENT>
                    -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT),打印的原始结果。收集有用的原始性能数据。
                    -e <NAME> <VALUE>: set argument <NAME> to <VALUE>,设置参数的名字。
                    -p <FILE>: 往外部文件写入数据。
                    -w: 一般为必填,否则无法看到测试结果。
 
 
Type 1    Run All Test
        该命令用于执行测试工程下面所有的测试类:
        adb shell am instrument -w com.example.test/android.test.InstrumentationTestRunner
        此处我的测试工程包名为com.example.test。
 
Type 2    Running tests from a specific test case
        如想执行某个测试类中所有测试,你可以使用以下命令:
        adb shell am instrument -w -e class  com.example.test.testA com.example.test/android.test.InstrumentationTestRunner       
        此处我的某一个测试类名为testA。
 
Type 3    Running a specific test by name
        如想执行某个测试类中某一个具体的测试,你可以使用以下命令:
        adb shell am instrument -w -e class com.huawei.mao.test.testA#testadd4 com.huawei.mao.test/android.test.InstrumentationTestRunner
        此处testadd4为测试类testA中的一个具体的测试。
 
Type 4    Running specific tests by category
       测试可以分为不同的类别,通过使用在这个类别的说明(测试注解)来区分,你可以运行某类测试注解的所有测试。你可以使用以下命令:
        adb shell am instrument -w -e size small com.example.test/android.test.InstrumentationTestRunner
        此处我执行的是包里所有用@SmallTest注解的测试。
 
创建自定义注解
        有时候我们需要执行一些特定的测试,也许这些测试不是固定的。此时我们可以通过一些自定义注解来实现,变更测试后只需要把测试的注解改变一下即可。以下是如何写一个自定义注解:
        package com.example.test;
 
        public @interface ImportantTest {
 
        }
        OK,现在我们可以使用命令:adb shell am instrument -w -e annotation ImportantTest com.example.test/android.test.InstrumentationTestRunner
不积跬步,无以至千里
原文地址:https://www.cnblogs.com/melody-emma/p/4178284.html