UiAutomator 2.0 命令行测试
UiAutomator 2.0 test from command line
我正在尝试使用 Android UIAutomator 进行一些简单的测试,我知道它需要由 Gradle 构建,因为 UIAutomator 2.0,我可以 运行我的简单测试仅通过 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)
下面是我的代码片段和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();
}
}
build.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
命令匹配。
作为 post 中的 build.gradle,您应该使用 "android.support.test.runner.AndroidJUnitRunner"
adb shell am instrument -w test.simple.uiatest/android.support.test.runner.AndroidJUnitRunner
对于你的包裹,试试这个:
adb shell am instrument -w test.simple.uiatest.test/android.support.test.runner.AndroidJUnitRunner
改用包 test.simple.uiatest.test
。
我正在尝试使用 Android UIAutomator 进行一些简单的测试,我知道它需要由 Gradle 构建,因为 UIAutomator 2.0,我可以 运行我的简单测试仅通过 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)
下面是我的代码片段和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();
}
}
build.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
命令匹配。
作为 post 中的 build.gradle,您应该使用 "android.support.test.runner.AndroidJUnitRunner"
adb shell am instrument -w test.simple.uiatest/android.support.test.runner.AndroidJUnitRunner
对于你的包裹,试试这个:
adb shell am instrument -w test.simple.uiatest.test/android.support.test.runner.AndroidJUnitRunner
改用包 test.simple.uiatest.test
。