gruszczy
gruszczy

Reputation: 42158

Android testing: TestCase is run but ActivityInstrumentationTestCase2 not

I am using Android Studio. I have two tests. One extends

import junit.framework.TestCase

the other

import android.test.ActivityInstrumentationTestCase2;

The first one is run from both Android Studio and command line:

~/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

But as you can see the activity test doesn't get invoked at all. Any Idea what I might be missing to have it run? My AndroidManifest in instrumentTest directory:

<?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>

and my Gradle file:

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'
}

Upvotes: 4

Views: 2422

Answers (2)

Dexter wu
Dexter wu

Reputation: 41

you have to go to terminal and type gradlew.bat.. i have that encountered that problem that its not running the ActivityInstrumentationTestCase2

Upvotes: 0

gruszczy
gruszczy

Reputation: 42158

The answer was hiding in the Android run logs all the time. My ActivityInstrumentationTestCase2 didn't have a proper ctor, because I just let the IDE construct the ctor from the base class.

Upvotes: 5

Related Questions