gpt4 book ai didi

android - UiAutomator 2.0 命令行测试

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:12 26 4
gpt4 key购买 nike

我正在尝试使用 Android UIAutomator 进行一些简单的测试,我知道自 UIAutomator 2.0 以来它需要由 Gradle 构建,我可以运行我的简单测试,它只通过 Android Studio 或命令行按下主页按钮通过“gradlew.bat cC”,我想知道如何使用 adb 命令运行它?

我试过了

adb shell am instrument -w test.simple.uiatest/android.test.InstrumentationTestRunner

按照建议here , 但我得到

INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{test.simple.uiatest/android.test.InstrumentationTestRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: test.simple.uiatest/android.test.InstrumentationTestRunner
at com.android.commands.am.Am.runInstrument(Am.java:951)
at com.android.commands.am.Am.onRun(Am.java:316)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:99)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:250)

下面是我的代码 fragment 和build.gradle,我做错了什么?

package test.simple.uiatest;

import android.support.test.uiautomator.UiDevice;
import android.test.InstrumentationTestCase;

public class ApplicationTest extends InstrumentationTestCase {
private UiDevice theDevice;

@Override
public void setUp() throws Exception {
super.setUp();
theDevice = UiDevice.getInstance(getInstrumentation());

theDevice.pressHome();
}

public void testName() throws Exception {
theDevice.pressHome();
}
}

构建.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"

defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
applicationId "test.simple.uiatest"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'LICENSE.txt'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0'
}

最佳答案

如果未安装测试 APK,或者如果 am instrument ... 命令中的 / 错误,就会出现您看到的错误。

要列出设备上可用的仪器测试,您可以运行 adb shell pm list instrumentation。你应该看到这样一行:

instrumentation:test.simple.uiatest/android.test.InstrumentationTestRunner (target=simple.target.app)

如果您没有看到与您的测试匹配的行,那么您需要安装测试 APK。如果已安装,请仔细检查 pm list instrumentation 输出的 test.simple.uiatest/android.test.InstrumentationTestRunner 部分是否与您的 am instrument 命令。

关于android - UiAutomator 2.0 命令行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com