SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Robotium
Test FrameWork
-Sampath Muddineni
Session Agenda
• Robotium… What is it?
• Where to get it and how to set it up
• “Normal” Android unit testing background
• Why Robotium is needed
• Using Robotium
• Robotium Tips/Tricks/Issues
• Complimentary tools
• Further Resources
• Q&A
Robotium – what is it?
• An open source test framework
• Used to write black or white box tests (emphasis is on black box)
• White box testing – testing software that knows and tests the internal
structures or workings of an application
• Black box testing – testing software functionality without knowledge of an
application (perhaps where the source code is not even available)
• Tests can be executed on an Android Virtual Device (AVD) or real device
• Built on Java (and Android) and JUnit (the Android Test Framework)
• In fact, it may be more appropriate to call Robotium an extension to the
Android test framework
Robotium Project Setup
• Install and setup JDK
• Install and setup Eclipse (optional)
• Install and setup Android Standard Development Kit (SDK)
• Supports Android 1.6 (API level 4) and above
• Install and setup Android Development Tools (ADT) for Eclipse (optional)
• Create Android AVD or attach device by USB
• Create an Android Test Project
• Download Robotium JAR and add to project classpath
• robotium-solo-X.X.jar (version 3.6 the latest as of this writing)
• From code.google.com/p/robotium/downloads/list
Background-Android JUnit Testing
• Android testing is based on JUnit
• You create test suites, classes (test cases), methods
• Organize tests into a Android Test project
• No annotations
• Test case classes can extend good-old-fashion JUnit3 TestCase
• To call Android APIs, base class must extend AndroidTestCase
• Use JUnit Assert class to check/display test results
• Execute tests using an SDK provided InstrumentationTestRunner
• android.test.InstrumentationTestRunner
• Usually handled automatically via IDE
Android Test Architecture
Robotium Project Setup
The “App” Used to Demo Today
Name should be in format : Last name,First name
Email Should end with “.com”
Should choose atleast one radio button
Should contain only numbers
Should choose atleast one checkbox
Robotium Project Setup
• Prerequisites
• Install and setup JDK
• Install and setup Eclipse (optional)
• Install and setup Android Standard Development Kit (SDK)
• Supports Android 1.6 (API level 4) and above
• Install and setup Android Development Tools (ADT) for Eclipse (optional)
• Create Android AVD or attach device by USB
• Create an Android Test Project
• Download Robotium JAR and add to project classpath
• robotium-solo-X.X.jar (version 3.6 the latest as of this writing)
Example Junit Test
Example Junit Test (Continued)
Robotium Solo API
• Robotium is all baked into one class - Solo – with many methods:
• clickX methods: clickOnButton, clickOnImage, clickOnText,…
• clickLongX methods: clickLongInList, clickLongOnScreen, clickLongOnText,…
• enterText
• drag
• getX methods: getButton, getCurrentActivity, getImage, getEditText, …
• goBack
• isX methods: isCheckBoxChecked, isRadioButtonChecked,isSpinnerTextSelected,
isTextChecked,…
• pressX methods: pressMenuItem, pressMenuItem, pressSpinnerItem, …
• scrollX methods: scrollToTop, scrollToBottom, …
• searchX methods: searchButton, searchEditText, searchText, …
• waitForX methods: waitForActivity, waitForText, …
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)
Example Robotium commands
public void testAdd() {
solo.enterText(0, "5");
solo.enterText(1,"3");
solo.clickOnButton("Add");
assertTrue(solo.searchEditText("8.0"));
}
Tips / Tricks / Issues
Robotium (and all JUnit tests) operate in the
same process (DVM) as the original app
• Robotium only works with the activities and views within the defined app
• For example: Can’t use intent to launch another app and test activity work
from that app
The popup keyboard is accomplished with a
bitmap in Android
• Robotium (or any unit test software) doesn’t see the “keys” as buttons or
anything.
Tips / Tricks / Issues
Use waitFor methods liberally.
• Especially if new screen opens or changes to what is displayed are
occurring.
• The waitFor methods tell Robotium to wait for a condition to happen
before the execution continues.
public void testGoodLogin() {
solo.enterText(0, “username");
solo.enterText(1, “password");
String label = res.getString(R.string.login_button_label); solo.clickOnButton(label);
String title = res.getString(R.string.title_activity_systemv); solo.waitForText(title);
solo.assertCurrentActivity("systemv", SystemVActivity.class); solo.getCurrentActivity().finish();
}
Tips / Tricks / Issues
RadioButtons are Buttons, EditText are Text,
etc…
• Getting the proper widget by index can be more
difficult
• Use of index also makes the test case more brittle
due to potential layout changes
• Consider clickOnButton(“Clear”) vs.
clickOnButton(6)
Tips / Tricks / Issues
Resources in Android are at a premium
(especially when test cases and App code are
running in same DVM).
• Use solo.finishOpenedActivities() in your tearDown method.
• It closes all the opened activities.
• Frees resources for the next tests
• Robotium has some difficulty with animations
• Robotium doesn’t work with status bar notifications
Tips / Tricks / Issues
Black Box Testing (when all you have is the
APK file) is a little more tricky.
• Recall in the demo, the test application wants the main activity name?
public TestDataCollectionActivity() {
super(DataCollectionActivity.class);
}
• You may not know this for a 3rd party/black box app.
• You can get the activity name by loading the APK to an AVD or device, running it, and watching the
logcat.
• The APK file has to have the same certificate signature as the test project.
• Probably have to delete the signature and then resign the APK with the Android debug key
signature.
•It’s easier than it sounds.
Tips / Tricks / Issues
• Robotium can automatically take screenshots
• solo.takeScreenshot( )
• Robotium can be run from the command line (using adb shell)
• adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner
• Robotium can test with localized strings
• solo.getString(localized_resource_string_id)
• Code coverage is a bit lackluster at this time
• Can be done with special ant task and command line tools
• Robotium does not work on Flash or Web apps.
Tips / Tricks / Issues
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
Tips / Tricks / Issues
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
Queriers??????????
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Android unittesting
Android unittestingAndroid unittesting
Android unittesting
QA Club Kiev
 

Was ist angesagt? (20)

Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021
 
Testing for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test AutomationTesting for Android: When, Where, and How to Successfully Use Test Automation
Testing for Android: When, Where, and How to Successfully Use Test Automation
 
Unit testing and Android
Unit testing and AndroidUnit testing and Android
Unit testing and Android
 
Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012
 
Android testing part i
Android testing part iAndroid testing part i
Android testing part i
 
Android Test Automation Workshop
Android Test Automation WorkshopAndroid Test Automation Workshop
Android Test Automation Workshop
 
A guide to Android automated testing
A guide to Android automated testingA guide to Android automated testing
A guide to Android automated testing
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)
 
Android unittesting
Android unittestingAndroid unittesting
Android unittesting
 
Utilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps AndroidUtilizando Espresso e UIAutomator no Teste de Apps Android
Utilizando Espresso e UIAutomator no Teste de Apps Android
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Android automation tools
Android automation toolsAndroid automation tools
Android automation tools
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Android development session 5 - Debug android studio
Android development   session 5 - Debug android studioAndroid development   session 5 - Debug android studio
Android development session 5 - Debug android studio
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
Dagger for android
Dagger for androidDagger for android
Dagger for android
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 

Ähnlich wie Robotium - sampath

Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
alii abbb
 
A. Sirota "Building an Automation Solution based on Appium"
A. Sirota "Building an Automation Solution based on Appium"A. Sirota "Building an Automation Solution based on Appium"
A. Sirota "Building an Automation Solution based on Appium"
DataArt
 
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Testing in Android: automatici, di integrazione, TDD e scenari avanzatiTesting in Android: automatici, di integrazione, TDD e scenari avanzati
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Alfredo Morresi
 

Ähnlich wie Robotium - sampath (20)

Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
 
A. Sirota "Building an Automation Solution based on Appium"
A. Sirota "Building an Automation Solution based on Appium"A. Sirota "Building an Automation Solution based on Appium"
A. Sirota "Building an Automation Solution based on Appium"
 
Testing on Android
Testing on AndroidTesting on Android
Testing on Android
 
Android Building, Testing and reversing
Android Building, Testing and reversingAndroid Building, Testing and reversing
Android Building, Testing and reversing
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
 
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
LDNSE: Testdroid for Mobile App and Web Testing (London Selenium Meetup)
 
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
Testing in Android: automatici, di integrazione, TDD e scenari avanzatiTesting in Android: automatici, di integrazione, TDD e scenari avanzati
Testing in Android: automatici, di integrazione, TDD e scenari avanzati
 
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19Robotium framework & Jenkins CI tools - TdT@Cluj #19
Robotium framework & Jenkins CI tools - TdT@Cluj #19
 
Robotium
RobotiumRobotium
Robotium
 
Automating JFC UI application testing with Jemmy
Automating JFC UI application testing with JemmyAutomating JFC UI application testing with Jemmy
Automating JFC UI application testing with Jemmy
 
Effective Android Development
Effective Android Development Effective Android Development
Effective Android Development
 
Getting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App TestingGetting Started with XCTest and XCUITest for iOS App Testing
Getting Started with XCTest and XCUITest for iOS App Testing
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Building an advanced automation solution based on Appium
Building an advanced automation solution based on AppiumBuilding an advanced automation solution based on Appium
Building an advanced automation solution based on Appium
 

KĂźrzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

KĂźrzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Robotium - sampath

  • 2. Session Agenda • Robotium… What is it? • Where to get it and how to set it up • “Normal” Android unit testing background • Why Robotium is needed • Using Robotium • Robotium Tips/Tricks/Issues • Complimentary tools • Further Resources • Q&A
  • 3. Robotium – what is it? • An open source test framework • Used to write black or white box tests (emphasis is on black box) • White box testing – testing software that knows and tests the internal structures or workings of an application • Black box testing – testing software functionality without knowledge of an application (perhaps where the source code is not even available) • Tests can be executed on an Android Virtual Device (AVD) or real device • Built on Java (and Android) and JUnit (the Android Test Framework) • In fact, it may be more appropriate to call Robotium an extension to the Android test framework
  • 4. Robotium Project Setup • Install and setup JDK • Install and setup Eclipse (optional) • Install and setup Android Standard Development Kit (SDK) • Supports Android 1.6 (API level 4) and above • Install and setup Android Development Tools (ADT) for Eclipse (optional) • Create Android AVD or attach device by USB • Create an Android Test Project • Download Robotium JAR and add to project classpath • robotium-solo-X.X.jar (version 3.6 the latest as of this writing) • From code.google.com/p/robotium/downloads/list
  • 5. Background-Android JUnit Testing • Android testing is based on JUnit • You create test suites, classes (test cases), methods • Organize tests into a Android Test project • No annotations • Test case classes can extend good-old-fashion JUnit3 TestCase • To call Android APIs, base class must extend AndroidTestCase • Use JUnit Assert class to check/display test results • Execute tests using an SDK provided InstrumentationTestRunner • android.test.InstrumentationTestRunner • Usually handled automatically via IDE
  • 8. The “App” Used to Demo Today Name should be in format : Last name,First name Email Should end with “.com” Should choose atleast one radio button Should contain only numbers Should choose atleast one checkbox
  • 9. Robotium Project Setup • Prerequisites • Install and setup JDK • Install and setup Eclipse (optional) • Install and setup Android Standard Development Kit (SDK) • Supports Android 1.6 (API level 4) and above • Install and setup Android Development Tools (ADT) for Eclipse (optional) • Create Android AVD or attach device by USB • Create an Android Test Project • Download Robotium JAR and add to project classpath • robotium-solo-X.X.jar (version 3.6 the latest as of this writing)
  • 11. Example Junit Test (Continued)
  • 12. Robotium Solo API • Robotium is all baked into one class - Solo – with many methods: • clickX methods: clickOnButton, clickOnImage, clickOnText,… • clickLongX methods: clickLongInList, clickLongOnScreen, clickLongOnText,… • enterText • drag • getX methods: getButton, getCurrentActivity, getImage, getEditText, … • goBack • isX methods: isCheckBoxChecked, isRadioButtonChecked,isSpinnerTextSelected, isTextChecked,… • pressX methods: pressMenuItem, pressMenuItem, pressSpinnerItem, … • scrollX methods: scrollToTop, scrollToBottom, … • searchX methods: searchButton, searchEditText, searchText, … • waitForX methods: waitForActivity, waitForText, …
  • 13. 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)
  • 14. Example Robotium commands public void testAdd() { solo.enterText(0, "5"); solo.enterText(1,"3"); solo.clickOnButton("Add"); assertTrue(solo.searchEditText("8.0")); }
  • 15. Tips / Tricks / Issues Robotium (and all JUnit tests) operate in the same process (DVM) as the original app • Robotium only works with the activities and views within the defined app • For example: Can’t use intent to launch another app and test activity work from that app The popup keyboard is accomplished with a bitmap in Android • Robotium (or any unit test software) doesn’t see the “keys” as buttons or anything.
  • 16. Tips / Tricks / Issues Use waitFor methods liberally. • Especially if new screen opens or changes to what is displayed are occurring. • The waitFor methods tell Robotium to wait for a condition to happen before the execution continues. public void testGoodLogin() { solo.enterText(0, “username"); solo.enterText(1, “password"); String label = res.getString(R.string.login_button_label); solo.clickOnButton(label); String title = res.getString(R.string.title_activity_systemv); solo.waitForText(title); solo.assertCurrentActivity("systemv", SystemVActivity.class); solo.getCurrentActivity().finish(); }
  • 17. Tips / Tricks / Issues RadioButtons are Buttons, EditText are Text, etc… • Getting the proper widget by index can be more difficult • Use of index also makes the test case more brittle due to potential layout changes • Consider clickOnButton(“Clear”) vs. clickOnButton(6)
  • 18. Tips / Tricks / Issues Resources in Android are at a premium (especially when test cases and App code are running in same DVM). • Use solo.finishOpenedActivities() in your tearDown method. • It closes all the opened activities. • Frees resources for the next tests • Robotium has some difficulty with animations • Robotium doesn’t work with status bar notifications
  • 19. Tips / Tricks / Issues Black Box Testing (when all you have is the APK file) is a little more tricky. • Recall in the demo, the test application wants the main activity name? public TestDataCollectionActivity() { super(DataCollectionActivity.class); } • You may not know this for a 3rd party/black box app. • You can get the activity name by loading the APK to an AVD or device, running it, and watching the logcat. • The APK file has to have the same certificate signature as the test project. • Probably have to delete the signature and then resign the APK with the Android debug key signature. •It’s easier than it sounds.
  • 20. Tips / Tricks / Issues • Robotium can automatically take screenshots • solo.takeScreenshot( ) • Robotium can be run from the command line (using adb shell) • adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner • Robotium can test with localized strings • solo.getString(localized_resource_string_id) • Code coverage is a bit lackluster at this time • Can be done with special ant task and command line tools • Robotium does not work on Flash or Web apps.
  • 21. Tips / Tricks / Issues 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
  • 22. Tips / Tricks / Issues 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