How to rotate activity, I mean: screen orientation change using Espresso?

前端 未结 6 1337
萌比男神i
萌比男神i 2020-12-30 00:11

I have decided that one of the testing criteria for my application tests with Google\'s Espresso is:

Test should maintain Activity state after s

6条回答
  •  青春惊慌失措
    2020-12-30 01:00

    If you have the only Activity in your test case, you can do:

    1. Declare you test Rule.

    @Rule
    public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class);
    

    2. Get you Activity and apply a screen rotation.

    mActivityTestRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    mActivityTestRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    That's a piece of pie!

提交回复
热议问题