美文网首页
Android Test

Android Test

作者: hello_cc | 来源:发表于2015-11-19 11:48 被阅读178次

Unit Test

  • 使用场景
    只是java,或者简单的依赖Android
  • 优点
    不用每次都启动真机或模拟器。
  • 使用说明
    1. 项目结构(app/src/main/java)
      测试路径(app/src/test/java)
    2. 依赖
dependencies {    
        // Unit testing dependencies    
        testCompile 'junit:junit:4.12'    
        // Set this dependency if you want to use Mockito
        testCompile 'org.mockito:mockito-core:1.10.19'    
        // Set this dependency if you want to use Hamcrest matching  
        testCompile 'org.hamcrest:hamcrest-library:1.1'
}
  1. 官方参考文档

Instrumented Unit Tests

  • 使用场景
    需要使用Android特性,如ContextSharedPreferences
    每次都要运行在真机或模拟器上。
  • 使用说明
    1. 添加测试的库
defaultConfig {
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
  1. 项目结构(app/src/main/java)
    测试路径(app/src/androidTest/java)
  2. 添加依赖
dependencies {    
        androidTestCompile 'com.android.support:support-annotations:23.0.1'    
        androidTestCompile 'com.android.support.test:runner:0.4.1'   
        androidTestCompile 'com.android.support.test:rules:0.4.1'    
        // Set this dependency if you want to use Hamcrest matching  
        androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
}
  1. 官方参考文档

参考

  1. Android Test官方文档,Github
  2. 测试模版GitHub
  3. Hamcrest,Mockito

相关文章

网友评论

      本文标题:Android Test

      本文链接:https://www.haomeiwen.com/subject/xjjlhttx.html