@sumio_tym (TOYAMA Sumio) Roppongi.aar #2 Portions of this presentation are reproduced from work created and shared by the Android Open Source Project[1] and used according to terms described in the Creative Commons 2.5 Attribution License[2]. [1] http://code.google.com/policies.html [2] http://creativecommons.org/licenses/by/2.5/
(github) • NTT Software Corporation – Provide technical assistance to Android Projects • Private activities – STAR (Software Test Automation Research Group Jp) – Some articles in @IT related to uiautomator/Appium: ʮεϚϗ͚ແྉγεςϜςετࣗಈԽπʔϧʯ http://www.atmarkit.co.jp/ait/kw/smapho_testtool.html 2
Instrumentation Test as of ver. 2.x. • The change makes you write a test method in mixture of Espresso and UI Automator. • We show a concrete example in this talk. 3
test (AUT) and test package: – run on the same process. – must be signed by the same certificate. • The test package can examine the AUT deeply. (e.g. fields of Activity) Quoted from http://developer.android.com/intl/ja/tools/testing/testing_android.html
– Single app testing – White-‐box style testing (Can access the interior of the AUT) • Architecture: Instrumentation test • Supported API level: ≥8 • Easier to write Quoted from http://developer.android.com/intl/ja/training/testing/ui-‐testing/espresso-‐testing.html
tests – Cross-‐app testing – Black-‐box style testing (Can not access the interior of the AUT) • Architecture: – Specialized architecture for UI Automator (as of 1.x) – Instrumentation test (as of 2.x) • Supported API level: – ≥16 (as of 1.x) – ≥18 (as of 2.x) • More complicated to write
based on Instrumentation Test. • So, you can write a test method in a mixture of them. • That widen a testable area: – Use Espresso for AUT (main purpose) – Use UI Automator for other apps (e.g. launched by the AUT) 9 UI Automator Becomes Friendly with Espresso
\ 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile \ 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2' } for Instrumentation Test for UI Automator for Espresso
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class); private UiDevice uiDevice; @Before public void setUp() { uiDevice = UiDevice. getInstance(InstrumentationRegistry.getInstrumentation()); } // YOUR TEST METHOD HERE } for Instrumentation Test for UI Automator
2. (In Settings App) Tap "ͱ࣌ࠁ" 3. Turn on/off "24࣌ؒදࣔ" 4. Press the back key twice 5. (In AUT) Enter "Hello World!" into the text box by using UI Automator
UiCollection dateTimeList = new UiCollection(new UiSelector(). className(ListView.class)); UiObject use24HourItem = dateTimeList.getChildByText(new UiSelector(). className(LinearLayout.class), "24࣌ؒදࣔ"); use24HourItem.clickAndWaitForNewWindow(); // go back to AUT. uiDevice.pressBack(); uiDevice.waitForIdle(); uiDevice.pressBack(); uiDevice.waitForWindowUpdate(AUT_PACKAGE_NAME, 1500L); // Enter "Hello World!" into the text box onView(withId(R.id.editText)). perform(typeText("Hello World!")); } UI Automator Espresso
Espresso – You can write a test method in a mixture of them. • Enables you to write a cross-‐app test more easily by using mainly Espresso. • A concrete example is available from https://github.com/sumio/UiAutomatorEspressoSample Thank you !