Android device testing: connectedAndroidTest does not execute my test case

I am trying to add some unit tests to my application. I am developing an application in Android Studio

This is what I did.

  • Added new package

  • Created a class in a new package that extends TestCase

  • The following method is added for the created class.

@SmallTest public void basicTest() { assertEquals("abc", "abc"); }

  • The following section defaultConfigis added inbuild.gradle

testApplicationId "newly.added.package.name" testInstrumentationRunner "android.test.InstrumentationTestRunner"

  • The following command is executed in the Android Studio terminal

gradlew.bat connectedAndroidTest

But when I checked the generated html report, it shows that 0 tests were performed.

I tried to follow, but none of them influenced the output of the command gradlew.bat connectedAndroidTest.

  • Incorrect package name added testApplicationIdin build.gradle.
  • Disconnected device

Why is my test case not running? What did I miss?

Below is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "my.package.name"
        minSdkVersion 12
        targetSdkVersion 18
        testApplicationId "my.package.name.tests"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile project(':my_sub_module1')
    compile project(':my_sub_module2')
    compile 'com.android.support:support-v4:21.0.2'
    compile files('libs/my_dependent_lib-1-7-4.jar')
    compile 'com.google.code.gson:gson:2.3'
}

repositories {
    mavenCentral()
}
+4
1

testInstrumentationRunner:

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Android Studio

Android

.

0

All Articles