如何在Espresso测试中启动服务?

Jas*_*son 7 android android-espresso

我想阻止服务启动,所以我可以在我的UI测试中独立测试它.通过startService活动中的呼叫按下按钮即可触发服务.

我已尝试使用Intents该类,但这似乎不适用于调用startService:

Intents.intending(IntentMatchers.hasComponent(MyService.class.getName())).respondWith(new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, null));

它似乎只与基于活动的意图相关.我没有在Espresso软件包中看到任何用于存根服务电话的内容.