I have onView(withId(R.id.check_box)).perform(click()), but i only want to do this if the check box is not already checked. How can I do this in espresso?
onView(withId(R.id.check_box)).perform(click())
You have something like this in your code:
@Rule public ActivityTestRule ActivityMainRule = new ActivityTestRule<>(ActivityMain.class);
Try
if (!ActivityMainRule.getActivity().findViewById(R.id.check_box).isChecked()) { onView(withId(R.id.check_box)).perform(click()) }