Android UI Testingwith uiautomator
Jana Moudrá | @Janamou | +JanaMoudrá
Me
Co-Founder at JuicymoGDG ČVUT Prague/GDG Prague
Web, Android, Design, Dart
about.me/janamou
Motivation
UI Testing
UI testing ensures that your application returns the correct UI output in response to a sequence
of user actions on a device.
http://developer.android.com/tools/testing/testing_ui.html
UI Testing
No knowledge of implementation
Testing and implementation
separated
Manual?
Time consumingNot repeatable
Error prone
Manual?
Time consumingNot repeatable
Error prone
We want to automate
Android?
Android?uiautomator
Android 4.1
Device
Tests in Java
How to test
in 3 steps
Create the App
1
Prepare the Test
2
Prepare the Test
Application is accessible
Application is on the device
Use uiautomatorviewer
Set development environment
Create the test
Development environment
Java project
+JUnit + uiautomator.jar + android.jar
Use uiautomatorviewer
Create the Test
extend the
UiAutomatorTestCase class
Use available classes
UiDeviceUiSelectorUiObject
UiCollectionUiScrollable
UiSelector
UiObject threeButton = new UiObject(
new UiSelector().text("3"));
threeButton.click();
UiSelector
UiObject urlForm = new UiObject(
new UiSelector()
.resourceId("com.android.browser:id/url"));
urlForm.setText("http://www.gug.cz");
getUiDevice().pressEnter();
What can I do with UiObject?
Use gesturesRetrieve attributes
Set textNo manipulation
We can use Asserts
assertEquals(threeButton.getText(), "3");
Run the Test
3
Run the Test
1) Build with Ant2) Push to device
3) Run the test
DEMO
Thank You!Questions???
about.me/janamou