Android 单元测试用例自动化:Robolectric 库 vs Android 测试框架 [英] Android unit test case automation: Robolectric library vs Android Testing framework

查看:32
本文介绍了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:

  1. 纯单元测试.我尝试让尽可能多的代码完全独立于 Android API,然后使用可以在任何 JVM 上运行的纯"单元测试.这些测试是最快的,它有助于保持不需要特定于 Android 的可移植代码.
  2. Robolectric 支持的单元测试.我的代码对 Android API 的依赖性很小,可以通过 Robolectric 阴影来满足,我使用 Robolectric 对其进行测试.与纯测试相比,Robolectric 的设置时间要多一些,但仍然比在模拟器上启动/运行要快.
  3. 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 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆