1. 程式人生 > >Espresso攔截不到Intent,Recorded intents:[]

Espresso攔截不到Intent,Recorded intents:[]

使用Espresso Intent 測試時,Recorded intents一直是空的,一直找不到原因,折騰了幾天才發現Espresso.Intents和Jpush有衝突,使用的是Jpush SDK3.0.8
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進行了初始化造成的,具體為什麼會有衝突,不太清楚

這裡寫圖片描述

解決方案:
註釋掉Jpush的初始化,再跑測試就通過了

這裡寫圖片描述

發了幾封郵件給極光,但並沒有沒有得到解決方案,可能目前國內不太注重自動化測試,懶得去折騰了