Android espresso 对于测试用例非常有用。但是当我使用 IdlingResource 时出现了一些问题。
我的 Activity 中有一个标志,我会在每次初始完成时将其设置为 true。
所以我的 IdlingResource 是这样的:
/**
* 等待所有初始化工作完成
*/
private class WaitPingSuccessIdlingResource implements IdlingResource {
private ChoiceServerActivity choiceServerActivity;
private ResourceCallback mResourceCallback;
public WaitPingSuccessIdlingResource(ChoiceServerActivity choiceServerActivity) {
this.choiceServerActivity = choiceServerActivity;
}
@Override
public String getName() {
return String.valueOf(hashCode());
}
@Override
public boolean isIdleNow() {
if (mResourceCallback != null && choiceServerActivity.isAllDataInited()) {
mResourceCallback.onTransitionToIdle();
}
boolean rst = choiceServerActivity.isAllDataInited();
Log.i("tonghu","WaitPingSuccessIdlingResource, isIdleNow(L94): rst " + rst);
return rst;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback callback) {
this.mResourceCallback = callback;
}
}
然后我这样注册:
Espresso.registerIdlingResources(new WaitPingSuccessIdlingResource(activity));
Log.i("tonghu", "ChoiceServerActivityTest, testPingSuccess(L42): 2222");
通常情况下,只有当isIdleNow()返回true时,才会打印第二条日志。
但现在我的日志是:
I/tonghu (23470): WaitPingSuccessIdlingResource, isIdleNow(L94): rst false
I/tonghu (23470): ChoiceServerActivityTest, testPingSuccess(L42): 2222
为什么当我的 IdlingResource 不空闲时第二个日志可以打印。
我的英文很差,有什么问题请告诉我!谢谢!
已编辑: 我已经解决了这个问题:
我看到类 IdlingResource 上有一条评论:
In such cases, test authors can register the custom resource and
{@link Espresso} will wait for the resource to become idle prior
to executing a view operation.
所以在注册Idling资源后,给任意一个view action:
Espresso.registerIdlingResources(new WaitPingSuccessIdlingResource(activity));
Espresso.onView(ViewMatchers.withId(R.id.list_view)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
最佳答案
同样的问题,发现注册idlingResources不会导致Espresso等待,但是除了Espresso.onView,还可以使用Espresso.onIdle()等待使已注册的 idlingResources 变为空闲状态。
终于找到了官方文档,引用自here :
Register idling resources before you need them.
The synchronization benefits associated with idling resources only take effect following Espresso's first invocation of that resource's isIdleNow() method.
The following list shows several examples of this property:
- If you register an idling resource in a method annotated with @Before, the idling resource takes effect in the first line of each test.
- If you register an idling resource inside a test, the idling resource takes effect during the next Espresso-based action. This behavior still occurs even if the next action is in the same test as the statement that registers the idling resource.
关于android - Espresso 空闲资源不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33120493/
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
我正在尝试将一个资源属性的默认值设置为另一个属性的值。我正在为我正在构建的tomcat说明书定义一个资源,其中包含以下定义。我想要可以独立设置的“名称”和“服务名称”属性。当未设置服务名称时,我希望它默认为为“名称”提供的任何内容。以下不符合我的预期:attribute:name,:kind_of=>String,:required=>true,:name_attribute=>trueattribute:service_name,:kind_of=>String,:default=>:name注意第二行末尾的“:default=>:name”。当我在Recipe的新block中引用我
这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw
你能解释一下吗?我想评估来自两个不同来源的值和计算。一个消息来源为我提供了以下信息(以编程方式):'a=2'第二个来源给了我这个表达式来评估:'a+3'这个有效:a=2eval'a+3'这也有效:eval'a=2;a+3'但我真正需要的是这个,但它不起作用:eval'a=2'eval'a+3'我想了解其中的区别,以及如何使最后一个选项起作用。感谢您的帮助。 最佳答案 您可以创建一个Binding,并将相同的绑定(bind)与每个eval相关联调用:1.9.3p194:008>b=binding=>#1.9.3p194:009>eva
我无法运行Spring。这是错误日志。myid-no-MacBook-Pro:myid$spring/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/lib/spring/sid.rb:17:in`fiddle_func':uninitializedconstantSpring::SID::DL(NameError)from/Users/myid/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/spring-0.0.10/li
我在RoR应用程序中有一个提交表单,是使用simple_form构建的。当字段为空白时,应用程序仍会继续下一步,而不会提示错误或警告。默认情况下,这些字段应该是required:true;但即使手动编写也行不通。该应用有3个步骤:NewPost(新View)->Preview(创建View)->Post。我的Controller和View的摘录会更清楚:defnew@post=Post.newenddefcreate@post=Post.new(params.require(:post).permit(:title,:category_id))ifparams[:previewButt