tl; dr it doesnβt look as if it were possible, given the current espresso intentions provided
I dug in the source code since I am trying to do something like this, and here is what I found:
The βintendedβ assistant works by looking at the list of recorded intentions. They are tracked by a callback that registers with the IntentMonitor instance when Intents.init () is called. The IntentMonitor instance is determined by the current Instrumentation. Each time IntentMonitor signalIntent () is called, the callback in Intents will be fired.
The problem is that signalIntent () never calls when you call activity.startService () with the intent. This is due to the fact that signalIntent () in the case of AndroidJunitRunner is called only by methods that are mapped to ExposedInstrumentationApi (which, as a rule, only correlate with various startActivity () methods). To use espresso-intents with startService (), it would seem that the tool hook for startService () would have to be available, which would allow signalIntent () to be called on IntentMonitor.
I have no experience adding custom Instrumentation to my test apk, but this will be my next research path. I will update my answer if I find anything that works.
source share