SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
Robotium Tutorial


                                    Mobile March
                                   March 21, 2013

                                           An Intertech Course




                    By Jim White, Intertech, Inc..
Course Name




                                                                         Stop by Intertech’s
                                                                         booth for a chance to
                                                                         win FREE Training.

       Or go to bit.ly.com/intertech-login

   Slides & demo code available at intertech.com/blog
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 2
Course Name




   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




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 3
Course Name




   Purpose
   • The main point/purpose to my talk…
           • There are wonderful test/QA tools available for Android!
           • There are no excuses for skipping unit testing in Android!




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 4
Course Name




   Jim White Intro
   • Intertech Partner,
           • Dir. of Training,
           • Instructor,
           • Consultant
   • Co-author, J2ME, Java in Small
     Things (Manning)
           • Device developer since before
             phones were “smart”
           • Java developer when “spring”
             and “struts” described your
             stride
   • Occasional beer drinker


Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 5
Course Name




   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



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 6
Course Name




   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)
           • From code.google.com/p/robotium/downloads/list



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 7
Course Name




   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
           • Android API supports JUnit 3 code style – not JUnit 4!
                   • No annotations
                   • Old JUnit naming conventions
   • 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


Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 8
Course Name




   Android Test Architecture
   • Architecturally, the unit testing project and app project run on the
     same JVM (i.e. DVM).




                                                                         Test case classes,
                                                                         instrumentation, JUnit,
                                                                         mock objects, etc.


Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 9
Course Name




   Robotium Project Setup
   • Add Robotium JAR to the Java                                         • Put Robotium in the build path
     Build Path                                                             order.




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 10
Course Name




   Android JUnit Project Setup




                                                       Demo



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 11
Course Name




   The “App” Used To Demo Today
   • Want to make sure data is
     entered.
   • Want to make sure data is
     valid.
           • Age is less than 122
           • Zip has 5 characters
   • Make sure a role is clicked.
   • Make sure clear does clear the
     fields.
   • Etc.




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 12
Course Name




   Example JUnit Test (Continued)
   public class TestDataCollection extends ActivityInstrumentationTestCase2<DataCollectionActivity> {

    DataCollectionActivity activity;

    public TestDataCollection() {                                               Extends AndroidTestCase –
      super(DataCollectionActivity.class);                                      provides functionality for testing a
                                                                                single Activity. Need to associate it
    }
                                                                                to an Activity type (like
                                                                                DataCollectionActivity)
    @Override
    public void setUp() throws Exception {
      super.setUp();                                                      Test case initialization method (just
      activity = getActivity();                                           like JUnit 3).
    }

    @Override
    protected void tearDown() throws Exception {
       activity.finish();                                                           Test case tear down method (just
       super.tearDown();                                                            like JUnit 3).
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 13
    }
Course Name




   Example JUnit Test (Continued)                                                 Test methods must
                                                                                  begin with “test”.
        public void testCheckNameClear() {
         final EditText name = (EditText) activity.findViewById(R.id.nameEdit);
         activity.runOnUiThread(new Runnable() {                                    Grab widgets by
            public void run() {                                                     their Android ID.
              name.requestFocus();              UI adjustments/ work must
            }                                   be done on UI thread
         });
         sendKeys("J I M");
                                                                                             TestCase,
                                                                                             TouchUtils
         Button button = (Button) activity.findViewById(R.id.clearButton);
                                                                                             provide limited UI
         TouchUtils.clickView(this, button);
                                                                                             maneuvering, but
         assertTrue("First name field is not empty.", name.getText().toString().equals(""));
                                                                                             again requires
       }
                                                                                          deep knowledge
   }
                                                                                          of the UI details


                                             Normal assert methods to
                                             check results.
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 14
Course Name




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 15
Course Name




   Why Android JUnit Isn’t Enough
   •     Requires deep knowledge of widgets
           •    Widget IDs
           •    Widget Properties
           •    What has focus
           •    Order of widgets
           •    Etc.
   •     Often requires deep knowledge of Android internals
           •    Especially around menus, dialogs, etc.
   •     Makes for brittle unit tests
           •    As the UI changes, the test often must change dramatically.
   •     Poor instrumentation
           •    Instrumentation is a feature in which specific monitoring of the interactions
                between an application and the system are made possible.
           •    Use of runOnUIThread to execute UI work that isn’t covered by TouchUtils or
                TestCase class.
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 16
Course Name




   Example Robotium
   • Use Robotium tests in JUnit test class
           • Same code as in TestDataCollectionActivity above…
           • With a few additions/changes.




           private Solo solo;

           @Override
                                                                          Add a Solo member
           public void setUp() throws Exception {                         variable and initialize it
             super.setUp();                                               during setUp( ).
             activity = getActivity();
             solo= new Solo(getInstrumentation(), getActivity());
           }



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 17
Course Name




   Example Robotium (Continued)
   • The new test method – greatly simplified via Robotium!

      public void testCheckNameClear() {
        solo.enterText(0, "Jim");                    // 0 is the index of the EditText field
        solo.clickOnButton("Clear");
        assertTrue("First name field is not empty.",solo.getEditText(0).
         getText().toString().equals(""));
      }


                                                                            Solo methods allow
                                                                            widgets to be selected
                                                                            and interacted with.




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 18
Course Name




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 19
Course Name




   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, …
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 20
Course Name




   Android Robotium Demo




                                                       Demo



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 21
Course Name




   Tips & Tricks
   • 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.




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 22
Course Name




   Tips & Tricks (Continued)
   • 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();
           }
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 23
Course Name




   Tips & Tricks (Continued)
   • 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)




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 24
Course Name




   Tips & Tricks (Continued)
   • 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




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 25
Course Name




   Tips & Tricks – Black Box Testing
   • 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. See referenced document for help.
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 26
Course Name




   Android Robotium Black Box Demo




                                                Black Box
                                                  Demo



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 27
Course Name




   Robotium Additional Features
   • 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.



Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 28
Course Name




   Complimentary Tools
   • Robotium Testroid Recorder
           •    Record actions to generate Android JUnit/Robotium test cases
           •    Run tests on 180 devices “in the cloud”
           •    Testdroid.com
           •    Commercial product (50 runs free, $99/month or ¢99/run)


   • Robotium Remote Control
           • Allows Robotium test cases to be executed from the JVM (on a PC)
                   • This allows Robotium to work with JUnit 4.
           • code.google.com/p/robotium/wiki/RemoteControl




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 29
Course Name




   Resources
   • These slides and demo code: intertech.com/blog
   • Google Robotium site
           • code.google.com/p/robotium
           • code.google.com/p/robotium/wiki/RobotiumTutorials
   • Tutorial Articles/Blog Posts
           •    devblog.xing.com/qa/robotium-atxing/
           •    www.netmagazine.com/tutorials/automate-your-android-app-testing
           •    robotiumsolo.blogspot.com/2012/12/what-is-robotium.html
           •    www.vogella.com/articles/AndroidTesting/article.html
           •    robotium.googlecode.com/files/RobotiumForBeginners.pdf
                   • excellent article for black box testing when all you have is the APK
   • Fundamentals of Android Unit Testing
           • developer.android.com/tools/testing/testing_android.html
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 30
Course Name




   Q&A
          • Questions – you got’em, I want’em




Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 31
Course Name




     Award-Winning Training and Consulting.




                  Visit     www.Intertech.com for complete details.
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 32
Course Name




     Intertech offers
     Mobile Training On:
                                 •     Android
                                 •     HTML5
                                 •     iOS
                                 •     Java ME
                                 •     jQuery
                                 •     Windows Phone




         Visit    ww.Intertech.com for complete course schedule.
Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 33
Course Name




                                                                      Stop by Intertech’s
                                                                      booth for a chance to
                                                                      win FREE Training.


          Or go to bit.ly.com/intertech-login

Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 34

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Mobile application testing
Mobile application testingMobile application testing
Mobile application testing
 
Basic Guide to Manual Testing
Basic Guide to Manual TestingBasic Guide to Manual Testing
Basic Guide to Manual Testing
 
What is-smoke-testing ?
What is-smoke-testing ?What is-smoke-testing ?
What is-smoke-testing ?
 
Appium Architecture | How Appium Works | Edureka
Appium Architecture | How Appium Works | EdurekaAppium Architecture | How Appium Works | Edureka
Appium Architecture | How Appium Works | Edureka
 
Test driven development with react
Test driven development with reactTest driven development with react
Test driven development with react
 
Automated UI Testing
Automated UI TestingAutomated UI Testing
Automated UI Testing
 
Android & iOS Automation Using Appium
Android & iOS Automation Using AppiumAndroid & iOS Automation Using Appium
Android & iOS Automation Using Appium
 
Mobile App Testing
Mobile App TestingMobile App Testing
Mobile App Testing
 
Automação de Teste para REST, Web e Mobile
Automação de Teste para REST, Web e MobileAutomação de Teste para REST, Web e Mobile
Automação de Teste para REST, Web e Mobile
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Appium: Automation for Mobile Apps
Appium: Automation for Mobile AppsAppium: Automation for Mobile Apps
Appium: Automation for Mobile Apps
 
React native development with expo
React native development with expoReact native development with expo
React native development with expo
 
Manual testing
Manual testingManual testing
Manual testing
 
Mobile Test Automation - Appium
Mobile Test Automation - AppiumMobile Test Automation - Appium
Mobile Test Automation - Appium
 
Automation using Appium
Automation using AppiumAutomation using Appium
Automation using Appium
 
Android testing
Android testingAndroid testing
Android testing
 
Types of test tools
Types of test toolsTypes of test tools
Types of test tools
 
Automation Testing With Appium
Automation Testing With AppiumAutomation Testing With Appium
Automation Testing With Appium
 
MobSF: Mobile Security Testing (Android/IoS)
MobSF: Mobile Security Testing (Android/IoS)MobSF: Mobile Security Testing (Android/IoS)
MobSF: Mobile Security Testing (Android/IoS)
 
Performance optimization for Android
Performance optimization for AndroidPerformance optimization for Android
Performance optimization for Android
 

Ähnlich wie Robotium Tutorial

Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
alii abbb
 

Ähnlich wie Robotium Tutorial (20)

Introduction to Robotium
Introduction to RobotiumIntroduction to Robotium
Introduction to Robotium
 
Guide to the jungle of testing frameworks
Guide to the jungle of testing frameworksGuide to the jungle of testing frameworks
Guide to the jungle of testing frameworks
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
Solit 2013, Автоматизация тестирования сложных систем: mixed mode automated t...
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
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
 
少し幸せになる技術
少し幸せになる技術少し幸せになる技術
少し幸せになる技術
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 
Utilizando expresso uiautomator na automacao de testes em apps android
Utilizando expresso uiautomator na automacao de testes em apps androidUtilizando expresso uiautomator na automacao de testes em apps android
Utilizando expresso uiautomator na automacao de testes em apps android
 
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
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Robotium - sampath
Robotium - sampathRobotium - sampath
Robotium - sampath
 
Junit mockito and PowerMock in Java
Junit mockito and  PowerMock in JavaJunit mockito and  PowerMock in Java
Junit mockito and PowerMock in Java
 
Android Workshop 2013
Android Workshop 2013Android Workshop 2013
Android Workshop 2013
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 

Mehr von Mobile March

Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt PrinsUsing Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
Mobile March
 
Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication
Mobile March
 
Guy Thier Keynote Presentation
Guy Thier Keynote PresentationGuy Thier Keynote Presentation
Guy Thier Keynote Presentation
Mobile March
 
Mobile March Olson presentation 2012
Mobile March Olson presentation 2012Mobile March Olson presentation 2012
Mobile March Olson presentation 2012
Mobile March
 

Mehr von Mobile March (20)

Cross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince BullingerCross-Platform Mobile Development with PhoneGap-Vince Bullinger
Cross-Platform Mobile Development with PhoneGap-Vince Bullinger
 
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
You Can’t Ignore the Tablet-Designing & Developing Universal Apps for Phones ...
 
Building Wearables-Kristina Durivage
Building Wearables-Kristina DurivageBuilding Wearables-Kristina Durivage
Building Wearables-Kristina Durivage
 
The Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-SparkThe Blossoming Internet of Things Zach Supalla-Spark
The Blossoming Internet of Things Zach Supalla-Spark
 
LiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel GerdeenLiveCode Cross-Platform Development-Joel Gerdeen
LiveCode Cross-Platform Development-Joel Gerdeen
 
The Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew DavidThe Mobile Evolution‚ Systems vs. Apps - Matthew David
The Mobile Evolution‚ Systems vs. Apps - Matthew David
 
Unity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh RuisUnity-Beyond Games! - Josh Ruis
Unity-Beyond Games! - Josh Ruis
 
IP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest GrumblesIP for Mobile Startups -Ernest Grumbles
IP for Mobile Startups -Ernest Grumbles
 
Using Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott LembckeUsing Chipmunk Physics to create a iOS Game - Scott Lembcke
Using Chipmunk Physics to create a iOS Game - Scott Lembcke
 
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt PrinsUsing Mobile to Achieve Truly Integrated Marketing - Curt Prins
Using Mobile to Achieve Truly Integrated Marketing - Curt Prins
 
Introduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroIntroduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason Shapiro
 
Developing Custom iOs Applications for Enterprise
Developing Custom iOs Applications for EnterpriseDeveloping Custom iOs Applications for Enterprise
Developing Custom iOs Applications for Enterprise
 
Product Management for Your App
Product Management for Your AppProduct Management for Your App
Product Management for Your App
 
Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication Dueling Banjos: Inter-app Communication
Dueling Banjos: Inter-app Communication
 
Guy Thier Keynote Presentation
Guy Thier Keynote PresentationGuy Thier Keynote Presentation
Guy Thier Keynote Presentation
 
Mobile March Olson presentation 2012
Mobile March Olson presentation 2012Mobile March Olson presentation 2012
Mobile March Olson presentation 2012
 
Bannin mobile march_2012_public
Bannin mobile march_2012_publicBannin mobile march_2012_public
Bannin mobile march_2012_public
 
Beginningi os part1-bobmccune
Beginningi os part1-bobmccuneBeginningi os part1-bobmccune
Beginningi os part1-bobmccune
 
Mobile march2012 android101-pt2
Mobile march2012 android101-pt2Mobile march2012 android101-pt2
Mobile march2012 android101-pt2
 
Mobile march2012 android101-pt1
Mobile march2012 android101-pt1Mobile march2012 android101-pt1
Mobile march2012 android101-pt1
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Robotium Tutorial

  • 1. Robotium Tutorial Mobile March March 21, 2013 An Intertech Course By Jim White, Intertech, Inc..
  • 2. Course Name Stop by Intertech’s booth for a chance to win FREE Training. Or go to bit.ly.com/intertech-login Slides & demo code available at intertech.com/blog Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 2
  • 3. Course Name 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 Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 3
  • 4. Course Name Purpose • The main point/purpose to my talk… • There are wonderful test/QA tools available for Android! • There are no excuses for skipping unit testing in Android! Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 4
  • 5. Course Name Jim White Intro • Intertech Partner, • Dir. of Training, • Instructor, • Consultant • Co-author, J2ME, Java in Small Things (Manning) • Device developer since before phones were “smart” • Java developer when “spring” and “struts” described your stride • Occasional beer drinker Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 5
  • 6. Course Name 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 Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 6
  • 7. Course Name 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) • From code.google.com/p/robotium/downloads/list Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 7
  • 8. Course Name 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 • Android API supports JUnit 3 code style – not JUnit 4! • No annotations • Old JUnit naming conventions • 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 Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 8
  • 9. Course Name Android Test Architecture • Architecturally, the unit testing project and app project run on the same JVM (i.e. DVM). Test case classes, instrumentation, JUnit, mock objects, etc. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 9
  • 10. Course Name Robotium Project Setup • Add Robotium JAR to the Java • Put Robotium in the build path Build Path order. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 10
  • 11. Course Name Android JUnit Project Setup Demo Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 11
  • 12. Course Name The “App” Used To Demo Today • Want to make sure data is entered. • Want to make sure data is valid. • Age is less than 122 • Zip has 5 characters • Make sure a role is clicked. • Make sure clear does clear the fields. • Etc. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 12
  • 13. Course Name Example JUnit Test (Continued) public class TestDataCollection extends ActivityInstrumentationTestCase2<DataCollectionActivity> { DataCollectionActivity activity; public TestDataCollection() { Extends AndroidTestCase – super(DataCollectionActivity.class); provides functionality for testing a single Activity. Need to associate it } to an Activity type (like DataCollectionActivity) @Override public void setUp() throws Exception { super.setUp(); Test case initialization method (just activity = getActivity(); like JUnit 3). } @Override protected void tearDown() throws Exception { activity.finish(); Test case tear down method (just super.tearDown(); like JUnit 3). Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 13 }
  • 14. Course Name Example JUnit Test (Continued) Test methods must begin with “test”. public void testCheckNameClear() { final EditText name = (EditText) activity.findViewById(R.id.nameEdit); activity.runOnUiThread(new Runnable() { Grab widgets by public void run() { their Android ID. name.requestFocus(); UI adjustments/ work must } be done on UI thread }); sendKeys("J I M"); TestCase, TouchUtils Button button = (Button) activity.findViewById(R.id.clearButton); provide limited UI TouchUtils.clickView(this, button); maneuvering, but assertTrue("First name field is not empty.", name.getText().toString().equals("")); again requires } deep knowledge } of the UI details Normal assert methods to check results. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 14
  • 15. Course Name Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 15
  • 16. Course Name Why Android JUnit Isn’t Enough • Requires deep knowledge of widgets • Widget IDs • Widget Properties • What has focus • Order of widgets • Etc. • Often requires deep knowledge of Android internals • Especially around menus, dialogs, etc. • Makes for brittle unit tests • As the UI changes, the test often must change dramatically. • Poor instrumentation • Instrumentation is a feature in which specific monitoring of the interactions between an application and the system are made possible. • Use of runOnUIThread to execute UI work that isn’t covered by TouchUtils or TestCase class. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 16
  • 17. Course Name Example Robotium • Use Robotium tests in JUnit test class • Same code as in TestDataCollectionActivity above… • With a few additions/changes. private Solo solo; @Override Add a Solo member public void setUp() throws Exception { variable and initialize it super.setUp(); during setUp( ). activity = getActivity(); solo= new Solo(getInstrumentation(), getActivity()); } Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 17
  • 18. Course Name Example Robotium (Continued) • The new test method – greatly simplified via Robotium! public void testCheckNameClear() { solo.enterText(0, "Jim"); // 0 is the index of the EditText field solo.clickOnButton("Clear"); assertTrue("First name field is not empty.",solo.getEditText(0). getText().toString().equals("")); } Solo methods allow widgets to be selected and interacted with. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 18
  • 19. Course Name Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 19
  • 20. Course Name 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, … Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 20
  • 21. Course Name Android Robotium Demo Demo Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 21
  • 22. Course Name Tips & Tricks • 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. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 22
  • 23. Course Name Tips & Tricks (Continued) • 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(); } Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 23
  • 24. Course Name Tips & Tricks (Continued) • 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) Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 24
  • 25. Course Name Tips & Tricks (Continued) • 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 Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 25
  • 26. Course Name Tips & Tricks – Black Box Testing • 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. See referenced document for help. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 26
  • 27. Course Name Android Robotium Black Box Demo Black Box Demo Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 27
  • 28. Course Name Robotium Additional Features • 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. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 28
  • 29. Course Name Complimentary Tools • Robotium Testroid Recorder • Record actions to generate Android JUnit/Robotium test cases • Run tests on 180 devices “in the cloud” • Testdroid.com • Commercial product (50 runs free, $99/month or ¢99/run) • Robotium Remote Control • Allows Robotium test cases to be executed from the JVM (on a PC) • This allows Robotium to work with JUnit 4. • code.google.com/p/robotium/wiki/RemoteControl Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 29
  • 30. Course Name Resources • These slides and demo code: intertech.com/blog • Google Robotium site • code.google.com/p/robotium • code.google.com/p/robotium/wiki/RobotiumTutorials • Tutorial Articles/Blog Posts • devblog.xing.com/qa/robotium-atxing/ • www.netmagazine.com/tutorials/automate-your-android-app-testing • robotiumsolo.blogspot.com/2012/12/what-is-robotium.html • www.vogella.com/articles/AndroidTesting/article.html • robotium.googlecode.com/files/RobotiumForBeginners.pdf • excellent article for black box testing when all you have is the APK • Fundamentals of Android Unit Testing • developer.android.com/tools/testing/testing_android.html Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 30
  • 31. Course Name Q&A • Questions – you got’em, I want’em Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 31
  • 32. Course Name Award-Winning Training and Consulting. Visit www.Intertech.com for complete details. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 32
  • 33. Course Name Intertech offers Mobile Training On: • Android • HTML5 • iOS • Java ME • jQuery • Windows Phone Visit ww.Intertech.com for complete course schedule. Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 33
  • 34. Course Name Stop by Intertech’s booth for a chance to win FREE Training. Or go to bit.ly.com/intertech-login Copyright © Intertech, Inc. • www.Intertech.com • 800-866-9884 Slide 34