使用es preSSO单元测试谷歌地图 [英] Using Espresso to Unit Test Google Maps

查看:328
本文介绍了使用es preSSO单元测试谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的长者preSSO做我的应用程序的一些UI测试。我有一个地图的片段,我展示它的一些项目,我通过调用我的后端得到的。

I am using Espresso to do some UI testing on my app. I have a fragment with a map, and I display some items on it that I get through a call to my backend.

当我点击一个标记,我正在做一些用户界面的事情

When I click on a marker, I'm doing some UI things

有没有什么方法可以让我做单元测试我有ES preSSO地图?

Is there any way I can do unit testing on my map with espresso ?

推荐答案

简短的回答: 随着ES preSSO是不是真的有可能。 一个解决方案可能是使用UIAutomator: 的https://developer.android.com/tools/testing-support-library/index.html#UIAutomatorhttps://developer.android.com/training/testing/ui-testing/uiautomator-testing.html

Short Answer: With espresso is not really possible. A solution might be to use UIAutomator: https://developer.android.com/tools/testing-support-library/index.html#UIAutomator https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html

所以,你需要:

1)增加摇篮依赖:

dependencies {
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0' }

2)确保你,即使你不使用它至少添加标题您的标记。

2) make sure you add at least title to your markers even if you're not using it.

3)编写测试,code是水木清华这样的:

3) Write the test, code is smth like this:

UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject marker = device.findObject(new UiSelector().descriptionContains("marker title"));
marker.click();

Exaplanation:

使用GoogleMap生成UI和也使访问即地图内容可以被看作是可访问节点信息的树。

GoogleMap generates UI and also makes it accessible i.e. map content can be seen as a tree of accessibility node info.

这是树是一种虚拟视图树,它不会再present真正的视图树。 我们会在以后讨论

This is tree is a virtual view tree, it does not represent the real view tree. We will come to this later

默认情况下,地图的contentDescription是谷歌地图,并标记为{markerTitle} {} markerSnippet。

By default the contentDescription of the map is "Google Map" and that of markers is "{markerTitle}. {markerSnippet}".

接下来的问题是,为什么不使用ES preSSO:

Then the question is so why not using espresso:

OnView为(withContentDescription(标记名称))执行(点击());

东阳它不会找到它,但是:

Beacause it wont find it, however :

onView(withContentDescription("Google Map")).perform(click());

将工作得很好。

will work just fine.

那么怎么来UIAutomator工作和Es preSSO不??

,因为它们使用不同的看法树木。

UIAutomator使用由AccessibilityService提供访问节点的信息树,而长者preSSO使用视图层次结构,从而处理所有的ViewGroup的所有儿童。可访问节点信息和视图层次可以或可以不映射一到酮。 在这种情况下

UIAutomator uses tree of accessibility node info provided by AccessibilityService, while Espresso uses the view hierarchy and thus processes all children of any ViewGroup. The accessibility node info and the view hierarchy may or may not map one-to-one. In this case

OnView为(withContentDescription(谷歌地图))

onView(withContentDescription("Google Map"))

发现不是的ViewGroup而是TextureView,这是不知道有孩子,使居preSSO不知道什么是画在那里。

finds not a ViewGroup but a TextureView, which is not known to have children so Espresso cannot know what is drawn in there.

瞧! :)

这篇关于使用es preSSO单元测试谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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