我正在尝试使用Android UIAutomator进行一些简单的测试。我知道自UIAutomator 2.0以来它需要通过Gradle构建,我可以通过Android Studio或命令行运行我的简单测试,只需通过“gradlew.bat cC”按home键即可。我想知道如何使用adb命令运行它?
我尝试过
adb shell am instrument -w test.simple.uiatest/android.test.InstrumentationTestRunner
根据这里的建议,但我遇到了问题。
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'
}