wxi
wxi

Reputation: 31

How to instrumentation-test android system apps

I searched this question but didn't find answers.

Suppose there is a system app, which is installed together with android system, e.g. Dialer app.

Now I want to unit-test or instrumentation-test this app. I don't want to use AOSP Android.mk. Are there alternative ways? e.g. Can I create a gradle project to test it?

Upvotes: 3

Views: 1019

Answers (2)

abstractx1
abstractx1

Reputation: 459

For instrumentation tests I personally create an independent app that consumes uiautomator: https://developer.android.com/topic/libraries/testing-support-library/index.html#UIAutomator

This allows simulation of a user:

@org.junit.Test
public void testCheckContact() throws InterruptedException {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    assertThat(device, notNullValue());
    device.pressHome();

    Context context = InstrumentationRegistry.getInstrumentation().getContext();
    Intent intent = context.getPackageManager().getLaunchIntentForPackage("systempackageName");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    ...
    ...

    PhoneActivityPage phoneActivityPage = new PhoneActivityPage();
    phoneActivityPage.clickContacts();

    assertEquals("Contacts", phoneActivityPage.getSelectedTab());
}

Where you can define PhoneActivityPage and the interface in a separate class within this independent test project.

I hope this helps.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007658

You can use the UiAutomator system to test arbitrary apps, including system ones. However, the inputs and outputs are somewhat limited.

Upvotes: 0

Related Questions