我如何可以提供参数测试功能,利用亚行外壳时仪表命令启动外壳、命令、仪表、参数

2023-09-12 09:09:13 作者:*你说我不够帅/.

我正在开发在Android中,我使用的仪器来测试手机应用程序。 仪器仪表是Android的ENV测试应用程序。

I am developing in Android, I am using instrumentation to test Phone application. Instrumentation is Android env to test applications.

有关,我用am命令与测试用例的名称。 我跑亚行,然后我进入亚行的shell,然后写在外壳的am命令。

For that I use am command with name of test case. I run adb, then I enter adb shell, then write in shell the am command.

我想这个am命令共同提供的参数。 我的意思,我想传递的参数测试由am命令启动。

I wish to deliver a parameter together with this am command. I mean that I wish to deliver parameters to the test launched by the am command.

是否有可能??? 请大家帮帮忙?

Is it possible ??? Please help ?

推荐答案

您可以通过一个数据的URI,MIME类型,甚至额外的am命令。

you can pass a data uri, mime type and even "extras" to the am command.

时许[开始|仪器]

我开始[-A<作用>] [-d< data_uri>]   [-t< MIME_TYPE>] [-c<类别> [-C<类别>] ...]   [-e< extra_key> < extra_value>   [-e< extra_key> < extra_value> ...]   [-n&其中;成分>]   [-D] [< URI>]

am start [-a <action>] [-d ] [-t <mime_type>] [-c <category> [-c <category>] ...] [-e <extra_key> <extra_value> [-e <extra_key> <extra_value> ...] [-n <component>] [-D] [<uri>]

时的仪器[-e&LT; arg_name&GT; &LT; arg_value&GT;] [-p&LT; prof_file&GT;] [-w]&lt;成分&GT;

am instrument [-e <arg_name> <arg_value>] [-p <prof_file>] [-w] <component>

您可以将它们作为临时演员,然后获取传递给它的附加功能。

You could pass them as "extras" and then get the extras that are passed to it.

您会通过他们这样的:

am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT 
  -e foo bar -e bert ernie -n my.package.component.blah

然后在code:

then in your code:

Bundle extras = this.getIntent ( ).getExtras ( );

if ( extras != null ) {
  if ( extras.containsKey ( "foo" ) ) {
    Log.d ( "FOO", extras.getString ( "foo" ) );
  } else {
    Log.d ( "FOO", "no foo here" );
  }

  if ( extras.containsKey ( "bert" ) ) {
    Log.d ( "BERT", extras.getString ( "bert" ) );
  } else {
    Log.d ( "BERT", "Bert is all alone" );
  }
} else {
  this.setTitle ( "no extras found" );
}