Sometimes you have to add a new activity/fragment to an existing application. This activity/fragment could be nested such that in order to access it the user must open the app and navigate through multiple parts of the UI before reaching it.
While developing this new activity/fragment, every time I make a change I have to recompile the whole app, launch it and navigate to the point where the new activity/fragment is shown. This is tedious and slows down the process.
Is there a way to directly launch the activity/fragment currently under development?
ADDENDUM:
Many have suggested to modify existing code or the manifest in order for the app to launch the new activity/fragment first:
Having to modify existing code was exactly what I wanted to avoid. It doesn't sound right to me. So I thought I could write an espresso test for this purpose and directly launch the activity/fragment from it. The problem is espresso keeps the activity/fragment only for the duration of the test so it is visible for a fraction of a second and then disappears.
This is what I was able to come up with thanks to @Code-Apprentice answer and this other answer: JUnit - stop it from exiting on finish?.
@RunWith(AndroidJUnit4.class)
public class VanillaActivityTest {
@Rule
public final ActivityTestRule<VanillaActivity> activityTestRule =
new ActivityTestRule<>(VanillaActivity.class, false, false);
@Test
public void blockingTest() throws Exception {
Intent intent = new Intent();
// Add your own intent extras here if applicable.
activityTestRule.launchActivity(intent);
CountDownLatch countdown = new CountDownLatch(1);
countdown.await();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With