安卓测试 : TestCase is run but ActivityInstrumentationTestCase2 not

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

但是正如您所见,根本没有调用 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/

相关文章:

android - 如何在行内排列元素,其中一个元素具有无限宽度?

android - 从三星 Galaxy Watch4 上的传感器检索心率数据

android - 我们为什么不创建具有最新版本和最旧版本的模拟器

Android 在设备上运行但在模拟器上崩溃

android - 使 Android 测试项目在没有源代码的情况下可用 ("make apk of the test-project")

java - 可绘制的波纹效果颜色错误

Android SDK 22 - SearchView 渲染问题

android - 有人可以为 Google Drive REST API v3 提供最新的 Android 指南吗?

android - android studio 中的 PowerMockito 抛出错误

android - getActivity() 方法在单元测试时无限期阻塞