在进行意式浓缩咖啡测试时确定片段变化 [英] Determine fragment change while espresso testing

查看:118
本文介绍了在进行意式浓缩咖啡测试时确定片段变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在android中测试我的应用程序,该应用程序由1个主要活动和我们在其中导航的多个片段组成.

I'm testing my application in android composed of 1 main activity and multiple fragments inside in which we navigate.

对于我的测试,我使用espresso,单击特定按钮后,我想检查当前片段是否已更改(带有按钮的部分可以).

For my tests I use espresso, and after a click on a particular button, I want to check if the current fragment has changed or not (the part with the button is ok).

那么,我该如何在espresso中检查片段是否仍然与单击按钮之前相同?

So, how can I do in espresso to check if the fragment is still the same than before the click on the button?

推荐答案

如果您确实想这样做,则可以

If you really want to do this, you can do

FragmentManager fragmentManager = getActivity().getFragmentManager()

并从fragmentManager获取有关后堆栈的信息.如果您的片段具有标签,则可以断言findFragmentByTag(tag)返回非空值.

and get information about the backstack from fragmentManager. If your fragment has a tag, you could assert that findFragmentByTag(tag) returns something non-null.

但是通常最好对视图层次进行断言.这是Espresso的设计目的,更符合黑匣子测试的精神.

But it's normally better to make assertions about the view hierarchy. It's what Espresso was designed for, and it's more in the spirit of black-box testing.

因此,我建议您找到新片段的一些区别特征,例如页面标题(如果有的话),并断言该视图是使用常用的Espresso方法显示的,例如

So I would suggest finding some distinguishing feature of the new fragment, such as the page title if there is one, and asserting that that view is present using the usual Espresso methods, e.g.

onView(withText("Page Two Title")).check(matches(isDisplayed()));

这篇关于在进行意式浓缩咖啡测试时确定片段变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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