uiautomator runtest命令行向jar文件传参

命令行如下:

adb shell uiautomator runtest  Test.jar -e runtype repeat -c com.yuchaolee.lau.MyTest.MTest

里面有个参数e,后跟的runtype和repeat分别是值的key和value。

代码段:

?
1
2
3
4
5
public void testLau() throws Exception { 
         Bundle bundle = getParams();
         String runType = bundle.getString( "runtype" );
         System.out.println(runType);
}




  • 支持三个子命令:rutest/dump/events
  • runtest命令-c指定要测试的class文件,用逗号分开,没有指定的话默认执行测试脚本jar包的所有测试类.注意用户可以以格式$class/$method来指定只是测试该class的某一个指定的方法
  • runtest命令-e参数可以指定是否开启debug模式
  • runtest命令-e参数可以指定test runner,不指定就使用系统默认。我自己从来没有指定过
  • runtest命令-e参数还可以通过键值对来指定传递给测试类的参数

同时我们这里会涉及到几个重要的类,我们这里先列出来给大家有一个初步的印象:

Class

Package

Description

Launcher

com.android.commands.uiautomator

uiautomator命令的入口方法main所在的类

RunTestCommand

com.android.commands

代表了命令行中‘uiautomator runtest'这个子命令

EventsCommand

com.android.commands

代表了命令行中‘uiautomator events’这个子命令

DumpCommand

com.android.commands

代表了命令行中‘uiautomator dump’这个子命令

UIAutomatorTestRunner

com.android.uiautomator.testrunner

默认的TestRunner,用来知道测试用例如何执行

TestCaseCollector

com.android.uiautomator.testrunner

用来从命令行和我们的测试脚本.class文件收集每个测试方法然后建立对应的junit.framework.TestCase测试用例的一个类,它维护着一个List<TestCase> mTestCases列表来存储所有测试方法(用例)

UiAutomationShellWrapper

com.android.uiautomator.core

一个UiAutomationwrapper类,简单的做了封装,其中提供了一个setRunAsMonkey的方法来通过ActivityManagerNativeProxy来设置系统的运行模式

UiAutomatorBridge

com.android.uiautomator.core

相当于UiAutomation的代理,基本上所有和UiAutomation打交道的方法都是通过它来分发的

ShellUiAutomatorBridge

com.android.uiautomator.core

UiAutomatorBridge的子类,额外增加了几个不需要用到UiAutomation的方法,getRotation



猜你喜欢

转载自blog.csdn.net/hzk594512323/article/details/46865655