1、配置测试环境

在app:gradle下配置


apply plugin: 'com.android.application'


android {
    compileSdkVersion 19
    buildToolsVersion "23.0.2"


    defaultConfig {
        applicationId "com.example.testshellcmd"
        minSdkVersion 14
        targetSdkVersion 19


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


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


dependencies {
    compile 'com.android.support:support-v4:19.1.0'


    // Required -- JUnit 4 framework
    testCompile 'junit:junit:4.12'


    androidTestCompile 'com.android.support:support-annotations:19.1.0'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'

}


2、在你要测试的类上,点击类名,右键,Go To --> Test



选择自动生成的方法以及要被测方法之后,选择测试类的存放路径


3、补充测试类


4、配置manifest文件,添加

<!-- 单元测试配置 -->

5、运行测试类,Run -- Edit Configurations... ,点击+号,选择Android Tests,在右侧完善信息



最后AS的工具栏中选择该测试类,并点击绿色三角形运行即可

更多相关文章

  1. 传智播客Android视频教程——第四天
  2. 关于安卓 TextView 添加点击事件
  3. android 可滑动的DatePicker和点击的DatePicker
  4. Android(安卓)可显示左上右下Drawable的TextView
  5. Android(安卓)自定义RadioButton样式 RadioGroup横向排列并分行
  6. Android(安卓)CTS的使用
  7. 〖Android〗存在多个Android设备时,使用Shell脚本选择一个Android
  8. Android(安卓)选择文件并返回路径
  9. Android中的时间日期选择器

随机推荐

  1. 记录android studio 遇到的错误和解决办
  2. Android listview与adapter用法(BaseAdap
  3. android volley json
  4. 博客地址
  5. Android ViewTreeObserver简介
  6. android 交叉编译工具的设置
  7. android AsyncTask 源码跟踪
  8. android把字符串内容保存到指定路径
  9. android 怎么动态设置button 的style
  10. Android Studio报错:Could not download k