Android测试:运行TestCase但不运行ActivityInstrumentationTestCase2

时间:2013-11-19 18:13:23

标签: 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.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>

和我的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'
}

2 个答案:

答案 0 :(得分:5)

答案一直隐藏在Android运行日志中。我的ActivityInstrumentationTestCase2没有合适的ctor,因为我只是让IDE从基类构建ctor。

答案 1 :(得分:0)

你必须去终端并输入gradlew.bat ..我遇到的问题是它没有运行ActivityInstrumentationTestCase2