SlideShare a Scribd company logo
Robotium
Easy Black-box Testing
for Android
Renas Reda / Hugo Josefson
Agenda
●
Vanilla vs Robotium
– Instrumentation testing
– Write readable tests, with 10x less code [DEMO]
– (Still) access all the powers of Instrumentation [DEMO]
●
Darker than Black box [DEMO]
●
Robotium with Maven [DEMO]
●
The future of testing on Android
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
• Blackbox method(?)
• 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
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);
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]
Darker than Black Box
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
The usual “Black box” way
• Two projects in Eclipse
– App project
– Test project
• Write test without looking at app's internals
The Darker than Black box way
• Any application's apk file
• One project in Eclipse
– App project
– Test project
• No access to original project
• Write test without any access to app's internals
Darker than Black Box
Test any APK w/o its source code
[DEMO]
Robotium with Maven
Maven
• Project management + Build tool
• Based on sane defaults
– Can be overridden with configuration
– Only configure what's different
• Plugins add functionality
– maven-android-plugin: build Android projects +
run Instrumentation tests
• Dependencies downloaded automatically
– Declare need for Robotium
→ Maven downloads jar
Declare need for Robotium
in test project
<dependency>
<groupId>com.jayway.android.robotium</groupId>
<artifactId>robotium-solo</artifactId>
<version>1.8.0</version>
</dependency>
Perform build and Run all Tests
including Robotium tests
$ mvn install
Maven with Robotium
Automating test execution
[DEMO]
The future of Testing
on Android
Google's Roadmap
?
Google's Roadmap
http://source.android.com/roadmap/
– Last entry “Beyond Q1 2009”:
– Support for WVGA and QVGA...
– Not keen on disclosing what they will /
will not release.
Google's Roadmap
http://source.android.com/roadmap/
– Last entry “Beyond Q1 2009”:
– Support for WVGA and QVGA...
– Page deleted
– Not keen on disclosing what they will /
will not release.
Robotium's Roadmap
for Instrumentation Testing
• Features we want to implement next
– Remote control
– Similar to Selenium RC
– Cucumber integration
– Generate screenshot on failure
– UI test coverage
• Features further down the line?
– Multidevice support
Robotium resources
Getting Started +
Robotium Developers discussion group:
www.robotium.org
Questions?
Robotium at Android Only 2010-09-29

More Related Content

PDF
Robotium Tutorial
PDF
Robotium - sampath
PPTX
Unit Testing Android Applications
PDF
Testing on Android
PDF
Android Testing: An Overview
PDF
Inside Android Testing
PPTX
Testing for Android: When, Where, and How to Successfully Use Test Automation
PDF
Learn How to Unit Test Your Android Application (with Robolectric)
Robotium Tutorial
Robotium - sampath
Unit Testing Android Applications
Testing on Android
Android Testing: An Overview
Inside Android Testing
Testing for Android: When, Where, and How to Successfully Use Test Automation
Learn How to Unit Test Your Android Application (with Robolectric)

What's hot (20)

PDF
A guide to Android automated testing
PDF
Android testing part i
PDF
Android Test Automation Workshop
PDF
Utilizando Espresso e UIAutomator no Teste de Apps Android
PPTX
[AnDevCon 2016] Mutation Testing for Android
PPTX
Getting Started with XCTest and XCUITest for iOS App Testing
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
PDF
Selenium Automation Testing Interview Questions And Answers
PDF
Selenium interview questions and answers
PDF
Selenium Basics Tutorial
DOCX
Selenium notes
PDF
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
PPTX
Testing android apps with espresso
PDF
Codeception introduction and use in Yii
DOCX
Selenium interview-questions-freshers
PDF
Introduction to Android Studio
ODP
Testing In Java
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
PDF
Selenium Handbook
PDF
Oh so you test? - A guide to testing on Android from Unit to Mutation
A guide to Android automated testing
Android testing part i
Android Test Automation Workshop
Utilizando Espresso e UIAutomator no Teste de Apps Android
[AnDevCon 2016] Mutation Testing for Android
Getting Started with XCTest and XCUITest for iOS App Testing
Efficient JavaScript Unit Testing, JavaOne China 2013
Selenium Automation Testing Interview Questions And Answers
Selenium interview questions and answers
Selenium Basics Tutorial
Selenium notes
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
Testing android apps with espresso
Codeception introduction and use in Yii
Selenium interview-questions-freshers
Introduction to Android Studio
Testing In Java
Acceptance & Functional Testing with Codeception - Devspace 2015
Selenium Handbook
Oh so you test? - A guide to testing on Android from Unit to Mutation
Ad

Similar to Robotium at Android Only 2010-09-29 (20)

PDF
Introduction to Robotium
PPTX
Robotium
PDF
Android Automation Using Robotium
PPTX
Android testing
PPT
Test Automation On Android Platform Using Robotium
PPTX
Robotium
PPTX
Different Android Test Automation Frameworks - What Works You the Best?
PDF
Android calculatortest
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
PDF
Hitchhiker's guide to Functional Testing
ODP
Unit Test Android Without Going Bald
PDF
Rockstar Android Testing (Mobile TechCon Munich 2014)
PDF
Android unittesting
PDF
Robotium framework & Jenkins CI tools - TdT@Cluj #19
PDF
[Ultracode Munich #4] Short introduction to the new Android build system incl...
PPTX
Android Apps Testing in 2019
PPTX
Android testing
PPTX
Android Testing
ODP
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
PPT
Test automationslides
Introduction to Robotium
Robotium
Android Automation Using Robotium
Android testing
Test Automation On Android Platform Using Robotium
Robotium
Different Android Test Automation Frameworks - What Works You the Best?
Android calculatortest
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Hitchhiker's guide to Functional Testing
Unit Test Android Without Going Bald
Rockstar Android Testing (Mobile TechCon Munich 2014)
Android unittesting
Robotium framework & Jenkins CI tools - TdT@Cluj #19
[Ultracode Munich #4] Short introduction to the new Android build system incl...
Android Apps Testing in 2019
Android testing
Android Testing
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Test automationslides
Ad

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
sap open course for s4hana steps from ECC to s4
NewMind AI Weekly Chronicles - August'25 Week I
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Robotium at Android Only 2010-09-29

  • 1. Robotium Easy Black-box Testing for Android Renas Reda / Hugo Josefson
  • 2. Agenda ● Vanilla vs Robotium – Instrumentation testing – Write readable tests, with 10x less code [DEMO] – (Still) access all the powers of Instrumentation [DEMO] ● Darker than Black box [DEMO] ● Robotium with Maven [DEMO] ● The future of testing on Android
  • 3. 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
  • 6. What's instrumentation testing? • Investigate interaction with UI • Pressing buttons, navigating menus • Blackbox method(?) • Takes time • Can use JUnit • Good for acceptance or system tests • Can be automated!
  • 7. 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
  • 8. Android built-in support • Tapping a view: TouchUtils.tapView(someView) • Pressing key (physical button): getInstrumentation(). sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) • Sending text: sendKeys(“some text”)
  • 9. 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
  • 10. Setting up instrumentation tests • Runs in emulator/device using JUnit 3 • Separate test project as normal
  • 13. 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);
  • 14. 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
  • 16. Robotium • Facts – Instrumentation testing framework – Add-on jar – Open Source (Apache 2) • Purpose – Simplify making tests
  • 17. • 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(?)
  • 18. Writing tests with Robotium • You use only one class: Solo • Test class like for normal instrumentation:
  • 20. Remember standard 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);
  • 21. Test Calculator with Robotium public void testAdd() { solo.enterText(0, "5"); solo.enterText(1,"3"); solo.clickOnButton("Add"); assertTrue(solo.searchEditText("8.0")); }
  • 22. 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)
  • 23. Writing Tests with Robotium + still access standard Instrumentation [DEMO]
  • 25. 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
  • 26. The usual “Black box” way • Two projects in Eclipse – App project – Test project • Write test without looking at app's internals
  • 27. The Darker than Black box way • Any application's apk file • One project in Eclipse – App project – Test project • No access to original project • Write test without any access to app's internals
  • 28. Darker than Black Box Test any APK w/o its source code [DEMO]
  • 30. Maven • Project management + Build tool • Based on sane defaults – Can be overridden with configuration – Only configure what's different • Plugins add functionality – maven-android-plugin: build Android projects + run Instrumentation tests • Dependencies downloaded automatically – Declare need for Robotium → Maven downloads jar
  • 31. Declare need for Robotium in test project <dependency> <groupId>com.jayway.android.robotium</groupId> <artifactId>robotium-solo</artifactId> <version>1.8.0</version> </dependency>
  • 32. Perform build and Run all Tests including Robotium tests $ mvn install
  • 33. Maven with Robotium Automating test execution [DEMO]
  • 34. The future of Testing on Android
  • 36. Google's Roadmap http://source.android.com/roadmap/ – Last entry “Beyond Q1 2009”: – Support for WVGA and QVGA... – Not keen on disclosing what they will / will not release.
  • 37. Google's Roadmap http://source.android.com/roadmap/ – Last entry “Beyond Q1 2009”: – Support for WVGA and QVGA... – Page deleted – Not keen on disclosing what they will / will not release.
  • 38. Robotium's Roadmap for Instrumentation Testing • Features we want to implement next – Remote control – Similar to Selenium RC – Cucumber integration – Generate screenshot on failure – UI test coverage • Features further down the line? – Multidevice support
  • 39. Robotium resources Getting Started + Robotium Developers discussion group: www.robotium.org Questions?