写作与robolectric Android的验收测试:怎么可能做到呢? [英] Writing Android acceptance tests with robolectric: how could it be done?

查看:220
本文介绍了写作与robolectric Android的验收测试:怎么可能做到呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用Android验收测试使用Robolectric写?这似乎是只有归类为一个单元测试框架。

Can Android acceptance tests be written using Robolectric? It seems to be classed only as a unit-testing framework.

为何不能被归类为接受或终端到终端的测试框架? (是否可以适用于这一目的?)

Why can it not be classed as acceptance or "end-to-end" testing framework? (Can it be adapted for that purpose?)

推荐答案

我觉得这可能是有点主观的,但我觉得这是回答的,所以这里是我采取它。

I think this may be a bit subjective, but I feel it's answerable, so here's my take on it.

它是一个端到端的测试框架?

这不可能是终端到终端,因为应用程序实际上并不在设备上运行,依赖可能被戏弄了,网络通常被嘲笑并测试没有准确地模拟用户是如何工作的与应用程序。生命周期进行了模拟和测试由你掌控。它甚至不上的Dalvik虚拟机运行,并有达尔维克和JVM(这里有一个简单但相关的例子区别:<一href=\"http://stackoverflow.com/questions/25668741/british-summer-time-bst-not-recognised-by-simpledateformat-timezone/25669688#25669688\">British夏令时 - BST不是SimpleDateFormat的时区识别)

It cannot be "end-to-end" because the application doesn't actually run on a device, the dependencies may be mocked out, network is usually mocked out and the tests don't simulate exactly how a user would work with the app. The lifecycle is simulated and controlled by you in the tests. It doesn't even run on the dalvik-VM and there are difference between dalvik and the JVM (here's a simple but relevant example: British Summer Time - BST not recognised by SimpleDateFormat timezone)

有关箱中,端至端测试只能与部署的应用程序正确地在屏幕上实现的,使用网络时,连接到它需要的服务器,获取信息,示出它与测试验证什么都可以屏幕上看到的。同样,这可能是主观的,但是这就是端到端的手段对我。

For me, an end-to-end test can only be achieved with a deployed application, using the network, connecting to the server it needs to, getting the information, showing it correctly on screen and the test verifying what can be seen on screen. Again, this may be subjective, but that's what e2e means to me.

它可以被用来编写验收测试?

这要看你从你的验收测试要什么,我见过的人不同的方式使用这个词,但我想说的答案是肯定。我们使用robolectric来测试我们的大多数业务逻辑,因为我们已经找到UI测试不可靠。

That depends on what you want from your acceptance tests, as I've seen people use this term differently, but I would say the answer is a definite yes. We use robolectric to test most of our business logic as we have found UI tests to not be reliable.

您可以用正确的数据实例化你的UI元素,与UI元素进行交互,检查它们在屏幕上显示的内容。我会说这涵盖了大量的地面。

You can instantiate your UI elements with the right data, interact with UI elements, check what they show on screen. I would say this covers a lot of ground.

这是说,有时这些测试是非常难写,我们得到了很多得不一样架构我们的code的(模型 - 视图 - presenter是最常见的,暗示)
对我们来说,关键是要有pretty哑巴的意见,并让presenter确定将显示在屏幕上。然后你测​​试presenter很大程度上与robolectric测试,你肯定可以写给这一系列的投入,我希望能在屏幕上看到这些输出式的试验。测试的观点进一步补充价值不大,因为它只是为你的presenter提供它的外壳。

That said, sometimes these tests were very difficult to write, and we got a lot out of architecting our code differently (Model-View-Presenter is most commonly suggested for that) The key for us was to have pretty "dumb" views and to let the presenter determine what will be shown on screen. Then you test that presenter heavily with robolectric tests and you can definitely write tests of the type "given this series of inputs, I expect to see these outputs on screen". Testing the view further adds little value because it's just a shell for what your presenter serves it.

我想介绍如何申请MVP到你的项目是一个SO回答范围,但我希望这有助于。

I think describing how to apply MVP to your project is outside the scope of a SO answer, but I hope this helps.

这篇关于写作与robolectric Android的验收测试:怎么可能做到呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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