Lah*_*ima 5 junit android unit-testing
我正在尝试向我的应用程序添加一些单元测试。我正在 Android Studio 中开发我的应用程序
这就是我所做的。
添加了新包
在新包中创建了一个扩展的类TestCase 
在创建的类中添加了以下方法
@SmallTest
public void basicTest() {
    assertEquals("abc", "abc");
}
defaultConfig中的部分build.gradletestApplicationId "newly.added.package.name"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
gradlew.bat connectedAndroidTest
但是,当我检查生成的 html 报告时,它显示运行了 0 个测试。
我尝试了以下操作,但它们都没有对命令的输出产生影响gradlew.bat connectedAndroidTest。
testApplicationId在 中添加了不正确的包名称build.gradle。为什么我的测试用例没有被执行?我错过了什么?
以下是我的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()
}
您应该使用以下 testInstrumentationRunner:
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
另外,单击Android Studio左侧的Build Variants ,然后选择
Android 仪器测试
在下拉菜单中。
| 归档时间: | 
 | 
| 查看次数: | 1608 次 | 
| 最近记录: |