起因
后来今天突然自己又抽风。又想去弄一下Android junit。
2、本文基于做过Eclipse开发使用过Android junit,如果Eclipse的Android Junit没有使用过,就我没有说过吧!
准备环境,配置
1、官网Demo地址:https://github.com/googlesamples/android-testing-templates.git
文档是:https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
2、环境
· 根据demo中
· 单纯想运行java的单元测试就引入
// Dependencies for local unit tests
testCompile 'junit:junit:' + rootProject.ext.junitVersion
testCompile 'org.mockito:mockito-all:' + rootProject.ext.mockitoVersion
testCompile 'org.hamcrest:hamcrest-all:' + rootProject.ext.hamcrestVersion
· 想运行Android的Junit得引入
// Android Testing Support Library's runner and rules
androidTestCompile 'com.android.support.test:runner:' + rootProject.ext.runnerVersion
androidTestCompile 'com.android.support.test:rules:' + rootProject.ext.rulesVersion
· 最后在 defaultConfig 节点添加
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}