如何处理Robolectric测试? [英] What to test with Robolectric?

查看:217
本文介绍了如何处理Robolectric测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我从根本上误解Robolectric的目的。我一直在争夺它一个星期已经,到目前为止,获得一个新的错误消息被认为是取得进展。我能够测试就像一个活动静态视图的一些基本的东西,但是,当一些更复杂的东西在起作用事情就土崩瓦解。我不得不延长Robolectric支持3-第三方库某些参数,应用程序兼容性的动作条和许多其他的东西这是非常耗时的,并没有真正记录任何地方,事物在pretty多冰川前进步伐。我开始以为我在一个错误的方式使用它,它根本不应该做我想做的事情。

It seems to me that I am fundamentally misunderstanding the purpose of Robolectric. I've been battling with it for a week already, and so far getting a new error message is considered as making progress. I am able to test some basic stuff like static views in an activity, but when something more complicated things come into play things just fall apart. I had to extend Robolectric to support 3-rd party libraries with certain parameters, Appcompat action bars and numerous other things which was extremely time-consuming and wasn't really documented anywhere, and things are advancing at a pretty much glacial pace. I am starting to think that I am using it in a wrong way and it simply isn't supposed to do what I want it to do.

一般的应用程序的逻辑非常简单,所以没有多少真正的单元测试,最复杂的东西在UI和远程API调用。是Robolectric只是应该做单元测试为Android比JUnit的,因为它可以运行在JVM上痛苦少,并且支持一些Android的班?也许,像居preSSO黑箱行为测试框架会更适合我的需要?但是我们用连续的整合,Robolectric是好的和容易建立运行CI服务器上的测试,而且我有种想保持这种方式。

The general app logic is quite straightforward so there isn't really much to unit test, the most complicated stuff is in the UI and remote API calls. Is Robolectric just supposed to make unit testing for Android less painful than with JUnit because it can run on the JVM and supports a few Android classes? Perhaps a black-box behaviour testing framework like Espresso would be more suitable for my needs? But we use continuos integration, and Robolectric was nice and easy to set up to run tests on the CI server, and I'd kind of like to keep it that way.

你用什么Robolectric呢?很多博客文章推荐它的生命周期活动测试,但因为我也是在Android的世界很新,我实在不明白它的目的,尤其是因为我的测试应用程序是人像,只。可能有人请给你用Robolectric什么的概述,你怎么办呢,preferably与code的例子,并解释为什么和这些测试是如何重要?

What do you use Robolectric for? A lot of blog posts recommend it for "activity lifecycle testing", but since I'm also quite new in the Android world, I don't really understand the purpose of it, especially since the app I'm testing is portrait-only. Could someone please give an overview of what you use Robolectric for, and how do you do it, preferably with code examples and explain why and how those tests are important?

推荐答案

我们使用它的:


  • 单元测试:从解析器和utils的所有组件,控制器和presenters

  • 集成/验收测试:应用程序的业务逻辑,每个屏幕(其中分为集成和/或验收测试)

我们不使用它(并发现它很难使用这些):

We don't use it for (and have found it difficult to use for these):


  • 测试网络层(我们运行通过以相同的方式将网络层注入测试数据的所有测试;解析器单独测试)

  • 用户流经不同的屏幕

如果您正在寻找更多的后者,或许居preSSO / Robotium更适合您的需求。而你绝对的可以的运行这些作为CI管道的一部分,但你需要投资建立了一段时间,或者像Appurify可以整合。

If you're looking for more of the latter, perhaps Espresso/Robotium are better suited for your needs. And you absolutely can run these as part of your CI pipeline, but you'll need to invest some time in setup, or integrating with something like Appurify.

如果你发现它很难写你的测试,它可能与你的应用程序是比您正在使用robolectric的方式架构的方式做多。见我的答案在这里为好,它可以帮助你:<一href=\"http://stackoverflow.com/questions/26154337/writing-android-acceptance-tests-with-robolectric-how-could-it-be-done/26161257#26161257\">Writing Android的验收测试与robolectric?怎么会做

If you are finding it very difficult to write your tests, it might have to do more with the way your app is architected than the way you're using robolectric. See my answer here as well, it might help you: Writing Android acceptance tests with robolectric: how could it be done?

这篇关于如何处理Robolectric测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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