我正在使用 Android Studio。我有两个测试。一个扩展
import junit.framework.TestCase
另一个
import android.test.ActivityInstrumentationTestCase2;
第一个是从 Android Studio 和命令行运行的:
~/Software/android-studio/sdk/platform-tools/adb shell am instrument -w -r -e debug false com.gruszczy.eisenhower.test/android.test.InstrumentationTestRunner
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.gruszczy.eisenhower.test.TasksReconciliatorTest:
INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
INSTRUMENTATION_STATUS: test=testRemoteInsert
INSTRUMENTATION_STATUS: class=com.gruszczy.eisenhower.test.TasksReconciliatorTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
INSTRUMENTATION_STATUS: test=testRemoteInsert
INSTRUMENTATION_STATUS: class=com.gruszczy.eisenhower.test.TasksReconciliatorTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_RESULT: stream=
Test results for InstrumentationTestRunner=.
Time: 0.04
OK (1 test)
INSTRUMENTATION_CODE: -1
但是正如您所见,根本没有调用 Activity 测试。知道我可能缺少什么让它运行吗?我在 instrumentTest
目录中的 AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gruszczy.eisenhower.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.gruszczy.eisenhower"
android:label="Tests for com.gruszczy.eisenhower"/>
</manifest>
和我的 Gradle 文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 18
testPackageName "com.gruszczy.eisenhower.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
}
dependencies {
compile 'com.google.apis:google-api-services-tasks:v1-rev19-1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.api-client:google-api-client-android:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.17.0-rc' exclude module: 'httpclient'
compile 'com.google.android.gms:play-services:3.2.25'
}
最佳答案
答案一直隐藏在 Android 运行日志中。我的 ActivityInstrumentationTestCase2
没有合适的构造函数,因为我只是让 IDE 从基类构造构造函数。
关于安卓测试 : TestCase is run but ActivityInstrumentationTestCase2 not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20078906/