ila*_*ana 25 instrumentation android
我正在开发Android,我正在使用仪器测试手机应用程序.Instrumentation是Android环境来测试应用程序.
为此,我使用带有测试用例名称的am命令.我运行adb,然后输入adb shell,然后在shell中写入am命令.
我希望与这个命令一起提供一个参数.我的意思是我希望将参数传递给am命令启动的测试.
可能吗 ???请帮忙 ?
Rya*_*rad 50
你可以将数据uri,mime类型甚至"extras"传递给am命令.
我[开始|仪器]
我开始[-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 <arg_name> <arg_value>] [-p <prof_file>] [-w] <component>
您可以将它们作为"额外"传递,然后获取传递给它的额外内容.
你会像这样传递它们:
am start -a android.intent.action.VIEW -c android.intent.category.DEFAULT
-e foo bar -e bert ernie -n my.package.component.blah
Run Code Online (Sandbox Code Playgroud)
然后在你的代码中:
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" );
}
Run Code Online (Sandbox Code Playgroud)
Ton*_*ter 14
将参数传递给:(例如,-e peerID SCH-I545)
adb -s 0915f98870e60701 shell am instrument -w -e class /
com.example.android.testing.uiautomator.BasicSample.sendInvite /
-e peerID SCH-I545 /
com.example.android.testing.uiautomator.BasicSample.test/android.sup /
port.test.runner.AndroidJUnitRunner
Run Code Online (Sandbox Code Playgroud)
在测试类中:
{
Bundle extras = InstrumentationRegistry.getArguments();
String peerID = null;
if ( extras != null ) {
if ( extras.containsKey ( "peerID" ) ) {
peerID = extras.getString("peerID");
System.out.println("PeerID: " + peerID);
} else {
System.out.println("No PeerID in extras");
}
} else {
System.out.println("No extras");
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
33861 次 |
最近记录: |