Android unit test case automation: Robolectric library vs Android Testing framework(Android 单元测试用例自动化:Robolectric 库 vs Android 测试框架)
问题描述
想知道哪个是为 Android 应用程序和库编写单元测试用例的更好选择:使用 Robolectric 库或坚持使用 Android 测试框架.我想在命令行运行测试套件,并希望它独立于配置模拟器或让设备连接到构建机器的需要.你们中有人对这两者或更好的东西进行比较分析吗?您的经验将极大地帮助我决定更好的解决方案.
Wondering which one is the better choice to write unit test cases for android apps and libraries: Using Robolectric library or sticking with Android Testing framework. I want to run test suite at commandline and want it be independent of need of configuring emulator or letting a device attached with build machine. Does anyone of you run a comparative analysis on both of these or something better? Your experiences will be great help me to decide on the better solution.
推荐答案
我使用分层系统,在这种情况下,我更喜欢尽可能早的层:
I use a tiered system, where I prefer earlier tiers where possible:
- 纯单元测试.我尝试让尽可能多的代码完全独立于 Android API,然后使用可以在任何 JVM 上运行的纯"单元测试.这些测试是最快的,它有助于保持不需要特定于 Android 的可移植代码.
- Robolectric 支持的单元测试.我的代码对 Android API 的依赖性很小,可以通过 Robolectric 阴影来满足,我使用 Robolectric 对其进行测试.与纯测试相比,Robolectric 的设置时间要多一些,但仍然比在模拟器上启动/运行要快.
- Android 框架测试.Robolectric 没有削减它的地方 - 要么是因为阴影不存在,要么是因为我大量使用 Android API(因此想针对真实事物进行测试) - 我编写了在模拟器/设备上运行的测试默认框架.
层级的意义在于让事情尽可能简单,这样可以让整个套件更快,并有助于促进更简洁的代码.
The point of the tiers is to keep things as simple as possible, which keeps the full suite faster and helps promote cleaner code.
这篇关于Android 单元测试用例自动化:Robolectric 库 vs Android 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 单元测试用例自动化:Robolectric 库 vs Androi


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01