21

In Android Studio when I debug instrumentation test, the test won't stop on any breakpoint. Debugging unit tests works. I have a simple instrumented test that only checks if username edittext is displayed:

@RunWith(AndroidJUnit4.class)
public class LogonActivityTest {

    @Rule
    public ActivityTestRule<LogOnActivity> mActivityRule = new ActivityTestRule<>(LogOnActivity.class, true, false);

    @Before
    public void setUp() throws Exception {
        mActivityRule.launchActivity(new Intent()); // breakpoint here
    }

    @Test
    public void testSimple() throws Exception {
        onView(withId(R.id.act_logon_et_username)).check(matches(isDisplayed())); // breakpoint here
    }
}

In build.gradle I have properly set

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

How can I debug instrumented tests? I'm using Espresso, Mockito and Dagger 2.

Tomask
  • 2,344
  • 3
  • 27
  • 37

2 Answers2

12

You can solve this a couple of ways Tomask.

You can pass the option -e debug true in the configuration for your test if you're invoking the test from the command line.

Otherwise, and more simply, you should choose Debug instead of Run when starting your tests from android studio. If you click Run for your test from android studio, the option -e debug false gets set and the test(s) will not stop execution at breakpoints.

Hope this helps!

atgrubb
  • 1,145
  • 7
  • 11
  • 6
    The problem is that although my tests are stoping the execution at the breakpoints, it only stops for few seconds and I'm unable to check what I want. – Leonardo Sibela Jul 29 '21 at 14:47
2

For me, switching to "Run Android instrumented Tests using Gradle" works fine.

Go to Android Studio -> Preferences and toggle this option.

enter image description here

If it is already enabled, try disabling it and hope for the best.

shubhamgarg1
  • 1,619
  • 1
  • 15
  • 20