2017-01-17 74 views
2

我搜索了這個問題,但沒有找到答案。如何使用儀器測試的Android系統應用

假設有一個系統的應用程序,這是與機器人系統,例如安裝在一起撥號程序。

現在我想單元測試或儀器測試這個程序。我不想使用AOSP Android.mk。有其他方法嗎?例如我可以創建一個Gradle項目來測試它嗎?

回答

1

對於儀器測試我個人創建一個獨立的應用程序,消耗uiautomator:https://developer.android.com/topic/libraries/testing-support-library/index.html#UIAutomator

這使得用戶的模擬:

@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()); 
} 

,您可以在一個單獨的類中的這個定義PhoneActivityPage和接口獨立測試項目。

我希望這會有所幫助。

+0

Thanks @ abstractx1,這就是我正在研究的內容,稍後會更新 – wxi

+0

它的工作原理。隨着它,我展示了手機應用程序,然後點擊撥號盤。 – wxi

+0

@wxi:太棒了!很高興它爲你工作。 – abstractx1