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

查看:157
本文介绍了Android的单元测试用例自动化:Robolectric库和Android手机,测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道哪一个是更好的选择编写单元测试用例的Andr​​oid应用程序和库:使用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.

推荐答案

我用一个分层系统,在这里我preFER前面层在可能的情况:

I use a tiered system, where I prefer earlier tiers where possible:

  1. 纯单元测试。我努力使尽可能多的code尽可能完全独立的Andr​​oid的API,然后用它可以在任何JVM上运行纯粹的单元测试。这些测试是最快的,它有助于保持code,有没有必要的Andr​​oid特有的便携性。
  2. Robolectric支持的单元测试。凡我code对Android的API的只有很小的依赖关系,可以通过Robolectric阴影满足,我有Robolectric测试。还有一点更设置时间Robolectric相比于纯粹的测试,但它仍然比开始/模拟器上运行得更快。
  3. 在Android框架的测试。凡Robolectric不剪 - 要么是因为阴影是不存在的,或者是因为我大量采用Android的API(因此要测试的真实的东西) - 我写的测试运行模拟器/设备上,与默认的框架。

该层次的意义在于让事情尽可能的简单,这使整套更快,有利于促进清洁code。

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库和Android手机,测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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