Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug instrumentation tests in Android Studio?

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.

like image 399
Tomask Avatar asked Apr 28 '16 15:04

Tomask


People also ask

What are instrumentation tests in Android?

Note: Instrumented test, also known as instrumentation tests, are initialized in a special environment that gives them access to an instance of Instrumentation. This class provides access to the application context and APIs to manipulate the app under test and gives instrumented tests their name.

What is instrumentation in mobile testing?

Instrumentation is a process to prepare the application for testing or automation. Part of the instrumentation process may add "instruments" that allow the testing framework to gain access to parts of the application. Perfecto provides tools for instrumenting mobile applications for different purposes.

How run all test cases in Android?

Right click on your root project and select "Create 'All Tests'..." Change the following options: Search for tests: In whole project.


1 Answers

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!

like image 83
atgrubb Avatar answered Sep 28 '22 12:09

atgrubb