1、在开发安卓的过程中,很少用的单元测试,终于在为了验证刷卡器读卡号的时候用到了,要测试卡号转换的规则和方法。使用过程中多多少少都会遇到问题,现做个记录
①在对应model的build.gradle中添加依赖和配置:
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
// Testing-only dependencies
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'junit:junit:4.12'
}
②在根目录的.idea文件中找到gradle.xml,在节点GradleProjectSettings下添加delegatedBuild
<GradleProjectSettings>
<option name="delegatedBuild" value="false" />
.......
</GradleProjectSettings>