@Before annotation must precede methods containing presetting. Initializing the necessary objects, getting the current session or current activity, you get an idea.
It replaces the old setUp() method from ActivityInstrumentationTestCase2, just as @After replaces tearDown() . This means that it is designed to be run before each test in the class, and it should remain that way.
There should be no ViewInteraction , no DataInteraction , no Assertions and View actions in this method, since this is not its purpose.
In your case, just remove the onView() call from setActivity() and place it inside the actual test methods, if necessary in each test method, for example:
@RunWith(AndroidJUnit4.class) @LargeTest public class WhenNavigatingToUsersView { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class); private MainActivity mainActivity; @Before public void setActivity() { mainActivity = mActivityRule.getActivity();
appoll
source share