Espresso检测不到Intent,Recorded intents:[]

来源:互联网 发布:南风知我意 吹梦到西洲 编辑:程序博客网 时间:2024/06/05 07:15

使用Espresso Intent 测试时,Recorded intents一直是空的,一直找不到原因,折腾了几天才发现Espresso.Intents和Jpush有冲突
Activity代码:
这里写图片描述

Espresso Intents UI测试代码:

这里写图片描述

报错

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.IntentMatcher: has component: has component with: class name: an instance of java.lang.String package name: an instance of java.lang.String short class name: is ".activity.PublishRepairActivity"Matched intents:[]Recorded intents:[]at dalvik.system.VMStack.getThreadStackTrace(Native Method)

发现是Application中对Jpush进行了初始化造成的,具体为什么会有冲突,不太清楚

这里写图片描述

解决方案1:
注释掉Jpush的初始化,再跑测试就通过了

这里写图片描述

解决方案2:
更新到Jpush SDK3.1.0 以上,再跑测试用例,即可跑通。
ps:我之前用的是Jpush SDK3.0.8