以下是全部的单元测试配置, 包含junit、espresso和uiautomator三个部分。
下面通过注释一一区分和介绍。
defaultConfig {
// junit 引入单元测试线程
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true //junit 开启超过65536 个方法数后不再报错
}
// junit 打开覆盖率统计开关,task里会多出一个createDebugCoverageReport任务,
//直接执行,所有方法都成功后可生成覆盖率报告
android {
buildTypes {
debug {
testCoverageEnabled = true
}
}
}
dependencies {
//noinspection GradleCompatible
// junit
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
// espresso
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
//uiautomator
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
}
网友评论