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

What's hot (20)

PDF
A guide to Android automated testing
jotaemepereira
 
PDF
Android testing part i
Kan-Han (John) Lu
 
PDF
Android Test Automation Workshop
Eduardo Carrara de Araujo
 
PDF
Utilizando Espresso e UIAutomator no Teste de Apps Android
Eduardo Carrara de Araujo
 
PPTX
[AnDevCon 2016] Mutation Testing for Android
Hazem Saleh
 
PPTX
Getting Started with XCTest and XCUITest for iOS App Testing
Bitbar
 
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
Hazem Saleh
 
PDF
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
PDF
Selenium interview questions and answers
kavinilavuG
 
PDF
Selenium Basics Tutorial
Clever Moe
 
DOCX
Selenium notes
wholcomb
 
PDF
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
Bitbar
 
PPTX
Testing android apps with espresso
Édipo Souza
 
PDF
Codeception introduction and use in Yii
IlPeach
 
DOCX
Selenium interview-questions-freshers
Naga Mani
 
PDF
Introduction to Android Studio
Michael Pan
 
ODP
Testing In Java
David Noble
 
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PDF
Selenium Handbook
Suresh Thammishetty
 
PDF
Oh so you test? - A guide to testing on Android from Unit to Mutation
Paul Blundell
 
A guide to Android automated testing
jotaemepereira
 
Android testing part i
Kan-Han (John) Lu
 
Android Test Automation Workshop
Eduardo Carrara de Araujo
 
Utilizando Espresso e UIAutomator no Teste de Apps Android
Eduardo Carrara de Araujo
 
[AnDevCon 2016] Mutation Testing for Android
Hazem Saleh
 
Getting Started with XCTest and XCUITest for iOS App Testing
Bitbar
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Hazem Saleh
 
Selenium Automation Testing Interview Questions And Answers
Ajit Jadhav
 
Selenium interview questions and answers
kavinilavuG
 
Selenium Basics Tutorial
Clever Moe
 
Selenium notes
wholcomb
 
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
Bitbar
 
Testing android apps with espresso
Édipo Souza
 
Codeception introduction and use in Yii
IlPeach
 
Selenium interview-questions-freshers
Naga Mani
 
Introduction to Android Studio
Michael Pan
 
Testing In Java
David Noble
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
Selenium Handbook
Suresh Thammishetty
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Paul Blundell
 

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

PDF
Introduction to Robotium
alii abbb
 
PPTX
Robotium
sara stanford
 
PDF
Android Automation Using Robotium
Mindfire Solutions
 
PPTX
Android testing
JinaTm
 
PPT
Test Automation On Android Platform Using Robotium
IndicThreads
 
PPTX
Robotium
Isuru Uyanage
 
PPTX
Different Android Test Automation Frameworks - What Works You the Best?
Bitbar
 
PDF
Android calculatortest
Vishal Dasa Redy
 
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
PDF
Hitchhiker's guide to Functional Testing
Wiebe Elsinga
 
ODP
Unit Test Android Without Going Bald
David Carver
 
PDF
Rockstar Android Testing (Mobile TechCon Munich 2014)
Danny Preussler
 
PDF
Android unittesting
QA Club Kiev
 
PDF
Robotium framework & Jenkins CI tools - TdT@Cluj #19
Tabăra de Testare
 
PDF
[Ultracode Munich #4] Short introduction to the new Android build system incl...
BeMyApp
 
PPTX
Android Apps Testing in 2019
Ivan Katunou
 
PPTX
Android testing
Bitbar
 
PPTX
Android Testing
Antoine Campbell
 
ODP
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Alfredo Morresi
 
PPT
Test automationslides
UMA MAHESWARI
 
Introduction to Robotium
alii abbb
 
Robotium
sara stanford
 
Android Automation Using Robotium
Mindfire Solutions
 
Android testing
JinaTm
 
Test Automation On Android Platform Using Robotium
IndicThreads
 
Robotium
Isuru Uyanage
 
Different Android Test Automation Frameworks - What Works You the Best?
Bitbar
 
Android calculatortest
Vishal Dasa Redy
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 
Hitchhiker's guide to Functional Testing
Wiebe Elsinga
 
Unit Test Android Without Going Bald
David Carver
 
Rockstar Android Testing (Mobile TechCon Munich 2014)
Danny Preussler
 
Android unittesting
QA Club Kiev
 
Robotium framework & Jenkins CI tools - TdT@Cluj #19
Tabăra de Testare
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
BeMyApp
 
Android Apps Testing in 2019
Ivan Katunou
 
Android testing
Bitbar
 
Android Testing
Antoine Campbell
 
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Alfredo Morresi
 
Test automationslides
UMA MAHESWARI
 
Ad

Recently uploaded (20)

PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
The Future of Artificial Intelligence (AI)
Mukul
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Ad

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?