How to determine with Robolectric that onBackPressed is called software?

I use Robolectric for unit tests. In my application, I have a method that programmatically calls onBackPressed. However, I do not know how to check whether this method is executed correctly with RoboLectric. I already tested it on the device, and the method works fine. But now: how can I confirm this with Robolectric?

+6
source share
1 answer
activity.initialize(); Button button = (Button) activity.findViewById(R.id.button_with_on_back_pressed_called); ShadowButton buttonShadow = (ShadowButton) Robolectric.shadowOf(button); OnClickListener onClickListener = buttonShadow.getOnClickListener(); onClickListener.onClick(button); ShadowActivity activityShadow = Robolectric.shadowOf(activity); assertTrue(activityShadow.isFinishing()); 
+11
source

Source: https://habr.com/ru/post/954230/


All Articles