public static <A extends Activity> void executeForActivity(final Class<A> activityClass, final Consumer<Intent> modifyIntent, final Consumer<ActivityScenario<A>> testCode) {
        final Intent intent = new Intent(ApplicationProvider.getApplicationContext(), activityClass);
        if (modifyIntent != null) {
            modifyIntent.accept(intent);
        }

        try (ActivityScenario<A> scenario = ActivityScenario.launch(intent)) {
            scenario.moveToState(Lifecycle.State.RESUMED);
            if (testCode != null) {
                testCode.accept(scenario);
            }
        }

    }
Helper to start activity scenario with modified intent and execute test code on it
main/src/androidTest/java/cgeo/geocaching/test/CgeoTestUtils.java