我的android 第8天 - 单元测试
16lz
2021-01-23
在实际开发中,开发android软件的过程需要不断地进行测试。而使用Junit 测试框架,则是正规的Android开发的必用技术,Android很好封装了Junit测试 框架,可以模拟发送事件和检测程序处理的正确性。
一、单元测试使用流程
•在AndroidManifest.xml的<application>中引入单元测试的类库<uses-library android:name="android.test.runner"/>
•设置要测试的用例<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="包名"/>
•编写测试用例 •继承AndroidTestCase •获取上下文getContext() •使用断言 assertEquals() •查看测试效果//构造需测试的业务类,传Context上下文参数
FileManager fileManager=new FileManager(getContext());
int expected=5;//期望的值
int actual=fileManager.deleteFile(6);//实际通过业务方法得到的值
//使用断言
assertEquals(expected, actual);
下载视频代码
更多相关文章
- GMS认证-Android VTS测试
- Android下junit单元测试、logCat的使用
- Android Studio 单元测试(instrumentation)
- Android 渗透测试学习手册(二)准备实验环境
- zz :Android测试之Monkey
- 利用ant对android项目进行测试,为集成测试提供定制信息
- Android USB Gadget复合设备驱动(打印机)测试方法
- 使用DDMS测试安卓手机APP的性能(android)