Andriod测试类和测试内容

1 Activity测试:基于Android instrumentation框架的测试。

Android提供的基础类是InstrumentationTestCase。主要的两个子类是ActivityInstrumentationTestCase2和ActivityUnitTestCase.
测试点:
- Input Validation: 包括对一个EditText的输入值检查,button的有效性验证,error messages是否正常提示。
- Lifecycle events: 包括当屏幕旋转时,app的activity状态是否可以保持
- Intents: 包括测试app是否可以正常处理intent filter里面所有功能
- Runtime configuration changes: 包括在app运行时,屏幕旋转或者语言的切换等是否导致app异常
- Screen sizes and resolutions: 包括所有支持的设备尺寸的测试

2 Service测试:Android提供了mock对象,针对Service进行测试。

Android提供的主要测试类是ServiceTestCase
测试点:
- 确保onCreate()和onDestory()在service启动和停止时调用了。
- 确保在调用Context.startService()后,Service能够正常处理多个请求。多个Context.startService()调用只会触发一个Service.onCreate().
- 测试Service的业务逻辑,包括异常值,算法等。

3 Content Provider测试:Content provider提供不同进程间数据交互的标准化接口。

Android提供的主要测试类是ProviderTestCase2
测试点:
- Test with resolver methods
- Test a public provider as a contract:包括测试provider暴露出来的常量,测试provider提供的所有URIs,测试无效的URIs.
- Test the standard provider interactions:大部分provider包括如下方法:query, insert, delete, update, getType, and onCreate()。针对这些方法进行验证。
- Test business logic

4 需要注意的测试内容

  • Change in orientation:设备方向的改变
  • Change in configuration: 系统语言和键盘的改变
  • Battery life:电池的消耗
  • Dependence on external resources:外部资源包括network, SMS, Bluetooth, GPS的可用性

5 Reference:

http://www.android-doc.com/tools/testing/what_to_test.html
http://www.android-doc.com/reference/junit/framework/TestCase.html
如下图,测试类的继承关系:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值