Вы можете сделать это легко с помощью Espresson Intents API :
В вашем тесте настройте IntentsTestRule, который будет записывать намерения, которые были уволены.
@Rule public IntentsTestRule<MyActivity> intentsTestRule =
new IntentsTestRule<>(MyActivity.class);
В своем тесте запустите свою деятельность, запустите тестируемый метод и подтвердите:
@Test
public void onClickManageServiceButton() {
// By default the rule launch your activity, so it's running by the time test starts
// Assuming the method to test is on your activity under test...
// You many need to find a View or mock one out to pass to the method.
mIntentsTestRule.getActivity().onClickManageServiceButton(null);
// Espresso will have recorded the intent being fired - now use the intents
// API to assert that the expected intent was launched...
Intents.intended(hasComponent(ServiceManagement.class.getName()));
}
Проверьте ссылки класса Intents и IntentMatchers , чтобы узнать больше о том, что вы можете сделать, чтобы утверждать, что намерения запущены.
Надеюсь, это поможет!