0% found this document useful (0 votes)
567 views

Robotium: Easy Black-Box Testing For Android

This document discusses Robotium, an open source framework that makes it easier to write black-box tests for Android applications. Robotium simplifies instrumentation testing by automatically finding views, adding timing delays, and following the current activity. Tests with Robotium are shorter and easier to write than standard instrumentation tests. The document provides an example comparing how to test a calculator app with standard instrumentation versus Robotium. It also outlines Robotium's future roadmap, which may include remote control capabilities and integration with Cucumber.

Uploaded by

nan_ais
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
567 views

Robotium: Easy Black-Box Testing For Android

This document discusses Robotium, an open source framework that makes it easier to write black-box tests for Android applications. Robotium simplifies instrumentation testing by automatically finding views, adding timing delays, and following the current activity. Tests with Robotium are shorter and easier to write than standard instrumentation tests. The document provides an example comparing how to test a calculator app with standard instrumentation versus Robotium. It also outlines Robotium's future roadmap, which may include remote control capabilities and integration with Cucumber.

Uploaded by

nan_ais
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Robotium

Easy Black-box Testing


for Android

Renas Reda / Hugo Josefson


Agenda
  Vanilla vs Robotium
-  Instrumentation testing
-  Robotium framework
-  Write readable tests, with 10x less code [DEMO]

  The future of Robotium


Black box testing?

•  ...doesn't know how an application is designed


at the code level...
–  bughuntress.com/analytics/glossary.html

•  ...done without reference to the source code...


–  www.sqablogs.com/jstrazzere/46/A+Glossary+of+Testing
+Terms.html
Instrumentation testing

Vanilla
vs
Robotium
Instrumentation Testing

(vanilla)
What's instrumentation testing?
•  Investigate interaction with UI
•  Pressing buttons, navigating menus
•  Takes time
•  Can use JUnit
•  Good for acceptance or system tests
•  Can be automated!
Android built-in support
•  Runs on device/emulator
•  JUnit 3 compatible framework
•  Allows direct control of user interface
–  Touches
–  Taps
–  Scrolling in lists
•  Can be started from Eclipse or shell
Android built-in support
•  Tapping a view:
TouchUtils.tapView(someView)

•  Pressing key (physical button):


getInstrumentation().
sendKeyDownUpSync(KeyEvent.KEYCODE_MENU)

•  Sending text:
sendKeys(“some text”)
Drawbacks and limitations
•  Required to know implementation details
•  You often have to manually add
Thread.sleep(500) to make tests work
•  Large apps can be very complex to test
•  Tests run slowly
–  Like if it would be done manually
–  Not suitable for TDD
Setting up instrumentation tests
•  Runs in emulator/device using JUnit 3
•  Separate test project as normal
Writing an instrumentation test
Testing a Calculator GUI
Writing an instrumentation test
// Find views
EditText num1 = (EditText) getActivity().findViewById
(com.calculator.R.id.num1);
EditText num2 = (EditText) getActivity().findViewById
(com.calculator.R.id.num2);
Button addButton = (Button) getActivity().findViewById
(com.calculator.R.id.add_button);

// Perform instrumentation commands


TouchUtils.tapView(this, num1);
sendKeys(KeyEvent.KEYCODE_1,KeyEvent.KEYCODE_5);
TouchUtils.tapView(this, num2);
sendKeys(KeyEvent.KEYCODE_5);
TouchUtils.tapView(this, addButton);

// Fetch result and compare it against expected value


String actual = num1.getText().toString();
String expected = "20.0";
assertEquals("Addition incorrect", expected,actual);
Running instrumentation tests
•  Started from Eclipse as “Android JUnit test”
•  Can also be started from command line:

adb shell am instrument -w com.package/


android.test.InstrumentationTestRunner
Instrumentation testing
with
Robotium
Robotium
•  Facts
–  Instrumentation testing framework
–  Add-on jar
–  Open Source (Apache 2)

•  Purpose
–  Simplify making tests
•  Benefits
–  Easy to write, shorter code
–  Automatic timing and delays
–  Automatically follows current Activity
–  Automatically finds Views
–  Automatically makes own decisions
– when to scroll etc.
–  No modification to Android platform
–  Test execution is fast

•  Current limitations
–  Tied to JUnit 3 Instrumentation on device
–  Tied to one app process
–  Needs initial Activity(?)
Writing tests with Robotium
•  You use only one class: Solo

•  Test class like for normal instrumentation:


Remember the Calculator GUI?
Remember standard
// Find views
instrumentation test?
EditText num1 = (EditText) getActivity().findViewById
(com.calculator.R.id.num1);
EditText num2 = (EditText) getActivity().findViewById
(com.calculator.R.id.num2);
Button addButton = (Button) getActivity().findViewById
(com.calculator.R.id.add_button);

// Perform instrumentation commands


TouchUtils.tapView(this, num1);
sendKeys(KeyEvent.KEYCODE_1,KeyEvent.KEYCODE_5);
TouchUtils.tapView(this, num2);
sendKeys(KeyEvent.KEYCODE_5);
TouchUtils.tapView(this, addButton);

// Fetch result and compare it against expected value


String actual = num1.getText().toString();
String expected = "20.0";
assertEquals("Addition incorrect", expected,actual);
Test Calculator with Robotium

public void testAdd() {


solo.enterText(0, "5");
solo.enterText(1,"3");
solo.clickOnButton("Add");
assertTrue(solo.searchEditText("8.0"));
}
Some Robotium commands
•  clickOnButton(String regex)
•  clickInList(int line)

•  enterText(int index, String text)


•  searchText(String regex)

•  clickOnMenuItem(String regex)
•  getCurrentActivity()
•  goBack(), goBackToActivity(String
name)
Writing Tests with Robotium
+ still access standard Instrumentation

[DEMO]
The future of Robotium
Development continues
•  Huge interest from the Android community
–  Contributors
–  New functionality
–  Improvements
–  Documentation
Robotium's Roadmap
•  Features further down the line?
–  Remote control
– Similar to Selenium RC
–  Cucumber integration
–  Generate screenshot on failure
–  UI test coverage
–  Multidevice support
Robotium resources

Getting Started +
Robotium Developers discussion group:

www.robotium.org

Questions?

You might also like