Android测试:TestCase已运行,但ActivityInstrumentationTestCase2未运行
我正在使用Android Studio。我有两个测试。一个延伸Android测试:TestCase已运行,但ActivityInstrumentationTestCase2未运行,android,android-studio,android-testing,Android,Android Studio,Android Testing,我正在使用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.gru
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
但是正如您所看到的,活动测试根本没有被调用。你知道我运行它可能会错过什么吗?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>
答案一直隐藏在Android运行日志中。我的
ActivityInstrumentationTestCase2
没有正确的ctor,因为我只是让IDE从基类构造ctor。您必须转到terminal并键入gradlew.bat。。我遇到的问题是它没有运行ActivityInstrumentationTestCase2
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'
}