Android的单元测试用例自动化:Robolectric库和Android手机,测试框架框架、单元测试、测试、手机

2023-09-04 08:06:18 作者:嶒經佷羙ら

想知道哪一个是更好的选择编写单元测试用例的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:

纯单元测试。我努力使尽可能多的code尽可能完全独立的Andr​​oid的API,然后用它可以在任何JVM上运行纯粹的单元测试。这些测试是最快的,它有助于保持code,有没有必要的Andr​​oid特有的便携性。 Robolectric支持的单元测试。凡我code对Android的API的只有很小的依赖关系,可以通过Robolectric阴影满足,我有Robolectric测试。还有一点更设置时间Robolectric相比于纯粹的测试,但它仍然比开始/模拟器上运行得更快。 在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.