Introduction to Android Espresso Testing and Spoon

Espresso UI test automation framework is Google’s de-facto testing platform for Android app developers.

The way it is easily used from within Android Studio and IntelliJ IDEA IDE’s makes it a powerful tool that differentiates it from other open-source cross-platform solutions such as Appium and other commercial tools.

Before drilling into basic setup and execution of an Espresso simple test, let’s first understand some of the basics:

  • Espresso is an Android only test automation framework (not cross platform like Appium/Selenium)
  • Espresso requires a separate APK package running in parallel with the application under test
  • Espresso is not Dev-Language Free framework like Appium (that supports Java, JS, Python, C#, Perl)

Positive Motivations to Use Espresso

  • The Espresso framework is embedded into the entire dev workflow and IDE, and that makes the adoption and leverage higher
  • Espresso can be used to do a quick post-commit validation of a fix or new code implementation, and also as part of a larger test scale within the CI workflow.
  • Espresso provides fast feedback to its users which is a big advantage since it is running on the device/emulator side-by-side with the app
  • Espresso supports annotations to determine the test execution scope (small/medium/large) which organizes the overall testing cycle for both dev and test
  • Espresso has unique synchronization method in its core making the tests less flaky and more robust. It will pass to the next test step in the code only once the view is available on the device screen in opposed to other tools that can easily fail without having timers, validation points and more.

Basic Espresso Framework Methods:

Espresso framework allows the automation developer to manipulate the test using 3 concepts:

  1. View Matchers
  2. View Actions
  3. View Assertions

basicses

As seen in the above definition, onView(xxx) of a specific object on the app screen, an Action will be performed and an Assertion will be made to validate the end result.

Espresso Setup

The setup within Android studio is quite simple, and there is plenty of documentation in the google community around it.

The developer will edit his build.Gradle file for the application under test to include the Espresso framework dependency, the JUnit version, and the InstrumentationRunner (see below example)

gradlesample

Once the above is done, it is time to create for the corresponding app the test class.

This class will need to include through Import, few libraries that are required by the Espresso test (below example)

import

Test Code Implementation

In order to develop an Espresso UI automation, the developer must have the unique object identifiers for the application under test.

To study the app objects (Hamcrest Matchers) the developer can use various methods:

  1. UIAutomation.bat tool that is built into the Android Studio SDK
  2. All resource ID’s should be automatically be stored in a dynamically generated R.java file
  3. Object spy within tools that supports Espresso (Perfecto and others).

Looking at a simple TipCalculator application, you can see through the UIAutomator spy, that the text box object ID is named bill_value

uiautomator

In the R.java file, it will look like this (choose the best method you find comfortable)

rjava

When implementing the Espresso test code, we will leverage the ObjectID as part of the onView method to perform a Click prior to entering an input value to that text box.

code1

In order to perform a type of value into the above Total Bill text box, we will use the 2nd method provided by Espresso, that is. Perform:

code2

Once we are done with the action, we would like to assure that the result of that action is as expected, and this is when the developer will use the assertion method .Check

code3

Finally, once the entire test suite is implemented and ready – running the test from Android Studio is very simple.

Select the Test class from the Edit Configurations menu in Android studio and chose run. Select your target (ADB connected device, cloud devices, emulators).

code4

At the end of a test, a basic test report will be provided to the user.

Running Espresso Tests in Parallel – Using Spoon

No test engineer or developer will be quite unless it validates the functionality of his app on multiple devices and emulators. For that, there is another widely used tool called Spoon (there are also cloud-based solutions as mentioned above that support parallel execution on real devices). This tool, will collect all the target devices (that are visible via adb devices) test results and aggregate them into one HTML view that can be easily investigated.

example_main

In order to leverage Spoon, please download the Gradle for spoon plugin and install it. Post installation, configure as follows

gradlespoon

By default, Spoon will run your tests on all ADB connected devices, however, if you want to run concrete devices and skip others in order to reproduce a specific defect on 1 device, you can configure spoon accordingly

spoon2

Good Luck!

Advertisements

3 Motivations That Made Me Switch From iOS to Android

As a mobile evangelist at Perfecto, i foresee the entire mobile and web space for the past 10+ years, following major trends both in the device/hardware front as well as the platform/OS (operating System) front.

I was an Apple user for the past 2 years, using an iPhone 6 Plus device both for my personal as well as my work daily activities. Last month i decided it’s time for a change and i replaced my iPhone with a Google Nexus 6P phablet.

Let me explain some of my reasons to that switch:

  1. Quality and Innovation
  2. Platform Restrictions
  3. Future Looking

vpcqffbw

Quality and Innovation

In the front of quality and/vs. innovation i found out that as a 2 year trend, Apple’s iOS was constantly straggling with quality that mostly came on top of innovative features and end user -experience. For the past 2 years Apple released 10 versions of iOS 8 stopping at a stable GA of iOS 8.4.1, while for iOS 9 Apple released 10+ versions stopping at a recent 9.3.5 GA release that addresses security issues. To compare this trend to Android platform – Android 5.0 Lollipop released in November 2014 and was enhanced till latest version of 5.1.1 (~5 versions in 2 years). Android Marshmallow 6.0 was released in October 2015 and since than only had an additional version of 6.0.1 release. Last month (August 22nd) Google released its new Nougat 7.0 release that is available to users (like me) that hold a Nexus device. iOS 10 is just around the corner with the iPhone 7 devices, but based on the current trend and enormous public Beta versions, it seems like no major changes are expected in the quality/release cadence.

In the Android history we see some major enhancements around sensor based capabilities for payment, logging in as well as UX (user experience) features such as multi window support (see below image), android Doze (battery saving capability). In iOS we also see enhancements around sensors like force-touch, apple pay however these features IMO come in short compared to the platform stability over the past 24 months and the platform constrains which i’ll highlight in the next section.

20160823_142250 Screenshot_20160823-141941

Platform Restrictions

From an ens user perspective, some of the important platform features involves the ability to customize his UX and look and feel of his personal device. Also having the ability to easily manage his media files such as photos and music with a reasonable storage availability. Apple flagship device with massive market share across regions is the iPhone 6/6S with a default storage (un-expandable) of 16GB – I hardly know a person who has this device/storage size that is happy with that, and does not need to constantly delete files, cancel auto savings of WhatsApp media files and alike.  In addition, continuously working with iTunes software as a dependency to media/songs sync is a pain and often i found myself losing my favorite music files or getting them duplicated by simply having to switch from 1 PC to another (people do that, and there are procedures that might have prevented this outcome but still). Compared to the above, most Android devices that are not coming with an external storage option are by default coming with a 64 GB internal memory, and in addition working with music file system is a simple and straight forward task to do.

Switching from my iPhone and iTunes to a Nexus device while having my Gmail account was a very simple thing to do, my music, photos and apps easily “followed” me to the Android device that is already running Android 7 in a stable way.

iOS is not all bad, don’t get me wrong – from an adoption perspective, and device/OS fragmentation this is by far a much better managed platform compared to Android that rolls out its latest GA version in a 4-6 months delay to a non-Nexus device (example: Samsung). In addition the iOS tablets are still a leader in that front with 4-6 years old tablets like iPad Air, iPad 2 that are the most commonly used tablets in the market that can still run iOS 9 OS versions. It is not the case when it comes to Android tablets that tend to be replaced by their end-users in a shorter period of time that iPads.

 

Market_Cal

Future Looking

From a future looking perspective, my opinion is that Google is still going to have a global market share advantage over Apple and will continue to innovate with less frequent releases due to quality than Apple. 2017 is going to show us a continuous battle between Android 7 and iOS 10 in a market that becomes more and more digital and mobile dependent, and with this in mind – the challenge of quality, innovation and less restrictions will be even more critical to independent users as well as large enterprises who are already today fully digital.

As an end-user, i would look at both Google and Apple and examine how their overall digital strategy will transform and enable easier connectivity with smart devices like watches etc., as well as less limited storage and device/OS customization. From a Dev and Test perspective i would assume we will continue to see growing adoption of open-source tools such as Espresso, XCTest UI, Appium etc. as a method of keeping up with the OS platform vendors – Only such open-source frameworks can easily and dynamically grow and support new features and functionalities compared to legacy/commercial tools which are slower to introduce new API’s and new capabilities  into their solutions.

IDC 2012 report around mobile and additional post on mobile testing

Hi

Redirecting to 2 new posts i’ve made on PerfectoMobile blog:

http://blog.perfectomobile.com/2012/11/02/idc-report-mobile-operating-systems-stats-for-q32012/

http://blog.perfectomobile.com/2012/10/26/testing-mobile-enterprise-business-critical-applications/

Enjoy

Eran

Latest news from the mobile world

Hi,

In the last couple of days and with the new iPhone5 announcement i wanted to gather the main highlights in one place 🙂

  • iPhone 5 (http://www.apple.com/iphone/) which was announced shall be available next week together with a possible launch of the new iOS6!
  • Details around the app store applications –> Total of 700,000 apps available in AppStore, while ~250,000 also ported to iPad
  • battle in the mobile world continues, and few great smartphones put themselves as leaders and competitors to the new iPhone 5:

** HTC One X – http://www.htc.com/www/smartphones/htc-one-x/ (4.7” Screen)

** Samsung Galaxy SIII – http://www.samsung.com/global/galaxys3/ (4.8” Screen)

** LG Optimus G – http://reviews.cnet.com/smartphones/lg-optimus-g-unlocked/4505-6452_7-35427825.html (4.7” Screen)

** Motorola Razr Maxx HD – http://www.engadget.com/2012/09/05/motorola-droid-razr-hd-maxx-hands-on-bigger-battery-beautiful/ (4.7” Screen)

** Sony Xperia S – http://www.gsmarena.com/sony_xperia_s-4369.php (4.3” Screen)

** Nokia Lumia 920 – http://www.nokia.com/global/products/phone/lumia920/ (4.5” Screen)

Eran Kinsbruner

Picking the right handsets for your project

Hi

We all know that the mobile world is dynamic, plenty of new handsets are being shipped at the same time in which we develop our product and testing on the (what we believe) is the “hottest” handsets in the market.

It is clear that being agile and fast in the way we develop, test and deploy our mobile products is a key to be attractive in the market, however it is also impossible to support all handsets and be ahead of the market.

So – The way to be up to date in the offering, is not simple but possible.

When you start developing your product keep in mind that by picking the “right” 10 handsets which are “hot” in the market you can reach the coverage of ~50% of the market (Note that there are lead devices which represent a whole family of handsets and can give you a lot of value by testing on it), as well if you go to ~30 devices you may reach up to ~80% coverage of the market.

How should you decide than?

The way to do the picking of handsets should combine the 2 following aspects:

– Market research

– Right family identification/lead devices

Market Research: The way to determine what is relevant in the market is to do some research and analysis – either through leading mobile blogs, or even simple – going through the leading mobile operators in the world, and seeing what they are currently selling (e.g. Vodafone global lists today in the top list of devices in Germany: Samsung Galaxy SIII, Samsung Galaxy SII, SEMC Xperia Arc S etc. – http://shop.vodafone.de/Shop/smartphones/, if you go to Vodafone UK you will see mostly the same ones, as well as HTC One X and others http://www.vodafone.co.uk/brands/android/index.htm)

Doing a matrix and unification of handsets between the world leading carriers in Europe/U.S/Asia should give you the lead handsets which you would like to support and test in the 3-6 months ahead (Per OS – Android, iOS, Windows Phone and BlackBerry).

Families: The aspect of family should be a subset of the above list If e.g you reached a common list of lets say 50 handsets, i am mostly certain that the list can be cut into half by doing proper comparison between the various handsets by their OS, Screen resolution and OEM (This can be done through sites like GSM Arena – http://www.gsmarena.com)  and minimizing the list by leads, members and families.

Please find attached to the post an up to date list of common handsets by OEM which is sold world wide these days to ease your pain 🙂  –> As you will see, there are a lot of similar handsets across all large operators which can show the main devices to focos on.

MobileWorldHandsetsDistribution

P.S: With regards to the leading Android/iOS tablets these days:

iOS – iPad 2 and iPad 3

Android – Samsung Galaxy Tab 10.1, Motorola Xoom, Asus Nexus 7, Dell Streak 7, Samsung Galaxy Tab 7, Sony Tablet S. Asus Transformer TF300, Asus Transformer TF700

Regards,

Eran

Cross Platform mobile development tool – Titanium

All

This is a Testing blog however i recently get a lot of questions around Mobile development/porting for cross platform projects (Android/iOS etc.).

For this cases there are several good and free tools out there which can be used such as PhoneGap (http://phonegap.com/download/), EggPlant (http://www.testplant.com/products/eggplant/for-cross-platform-testing/) and Titanium.

In this short post i will just point you out to the tool and give a very high level details about it for you guys to go and try it out for yourself

Titanium is a free tool by Appcelerator (http://www.appcelerator.com/platform/titanium-sdk) which allows quite quickly to develop a cross platform mobile application which can be than deployed on iOS and Android Phones/Emulators and also PC Web browsers.

The tool allows to develop in Java Script and customize your resources pending the operating system you which to deploy on:

You need to have on your machine the Android SDK and point its location in the Titanium SDK to allow execution and debugging on the Android Emulator.

You have through the SDK options to create new project from samples or templates (HTML5, Tabbed APP and more).

Feel free to give it a try and comment

Regards,

Eran Kinsbruner

Mobile project planning

Hi

Up until now i covered in the various posts the aspects of Mobile testing, trends, tools for automation, mobile platforms etc.

All of the above does not help much if the mobile project is not well planned in advanced with SMART milestones, efficient choices of devices (lead/gold devices), right tools and Agile ALM (Application life-cycle management).

In this short post i will advise the most important project milestones and how to define them.

First milestone:

Product definition and feature list –> In this milestone the product management ought to chose the supported platforms and devices for the project (based on thorough market research world wide and based on the projected release date which should be relevant for the selected devices), the project scope (the feature set should be well defined, the supported languages/localizations should be defined, the required certifications (Google CTS, Google Market, Apple App Store certification and more) should be clear, the target customers and of course the projected release date.

Not to forget the UI/UE aspect which is a critical aspect in any mobile project (Not only because the OS requirements but also for the end users).

Second Milestone:

– Core team build up and preliminary work plan implementation, staffing etc.

– Purchasing/ordering of equipment as needed, tools for development and automation should be brought up for approval

– High level Test Plan and Product specification should be developed during that milestone and approve by the core team

Third Milestone:

– Product development

– Unit test development

– Test development on the lead/gold devices per platform (Manual and Automated)

– Documentation creation (As needed and as defined by product)

– Sanity testing on supported devices, emulators, and cloud based handsets.

fourth Milestone:

– Feature complete

– Test development complete

– Full cycle execution on lead devices

– Porting kick off –> Building of subset devices (Either from the lead devices family or new families) versions for testing (Only sanity testing is required for devices within the lead devices family, while full cycles on new family members)

** Family can be defined by a group of devices from the same OEM with the same OS and Screen resolution (e.g. Samsung Galaxy S and Samsung galaxy S Plus are related to the same family –> http://www.gsmarena.com/samsung_i9001_galaxy_s_plus-3908.php ; http://www.gsmarena.com/samsung_i9000_galaxy_s-3115.php).

Fifth Milestone:

– In this stage the project should be well tested, debugged, ported to at least several devices and families, as well as documentation should be ready, certification status should be GREEN, and the bug trends for the project should also be minimal, quality criteria is mostly met.

– Project release to the various markets for approval is being done

– Based on approval and if needed pre-customer approval the project is released!!

The above is just in a nutshell list of items which i feel are a must in a common project plan for a mobile project, i might have missed few items, or the order can be different in few companies, but the above should bring you to a safe release if followed properly.

Thanks,

Eran Kinsbruner

JAMO Solutions – Mobile test automation tool

Hi,

I am sure that most mobile testers heard about JAMO solutions, but if not than i will briefly introduce this solution.

In past blogs i mentioned few powerful automation tools such as PerfectoMobile, Keynote Device anywhere, SeeTest by ExperiTest and FoneMonkey (MonkeyTalk).

Except of the Monkey Talk – all others are commercial tools and not free.

Jamo is also a commercial and not free solutions which comes in various licensing models from a company based in Belgium  (http://www.jamosolutions.com/editions.html).

The solutions is based on a plug in to various of IDE’s such as QTP (HP), Eclipse, and Visual Studio, which than allows connectivity over USB or WiFi through a Device manager to the mobile platform (iOS, Android, BlackBerry and Windows Mobile) on which an agent is also installed to provide the full control and automation via record/replay, easy to input text utils etc.

For Android OS device automation using eclipse, you can see a short demo of the tool and its methodology:


In the same manner as the video above users can automate their scenario’s through QTP or Visual studio for the various OS platforms.

For more information or inquiries please contact Jamo through their web site:

http://www.jamosolutions.com/home.html

Regards,

Eran

Mobile testing using Benchmarks

Hi,

We know that many devices vary between each other in their HW capabilities, meaning – the fact that 2 devices by 2 different or similar OEM’s, running the same OS/different OS version will score differently in a benchmark run or a performance test.

This is usually due to hardware differences, defects related to memory allocation, and others.

The use of mobile benchmarks had become quite significant and useful and can allow the application developers and testers to do objective testing on many different devices using a benchmark tool and get unique scores.

By comparing the overall score among the devices under test they can reach a conclusion which device has the higher performance and decide to either use it as “Gold” device for its porting platform, or if the score is extremely low, use it for testing when that device serves as the low performer in the list allowing the team to gain some prerequisite information on how their application would run on the device/s.

The benchmarks are usually downloaded for free from the Android or App store markets, and allows at the end of the quick test run to compare the device score with other devices which ran in the past and see the overall position of the device under test in compare to the market.

Usually the tests involve mathematical calculations (such as finding the prime number from a list), string sorting or number sorting, 2D/3D gaming with FPS calculations, reading and writing to a memory of the device (SD Card etc.), and some other CPU tests.

I strongly recommend to use such tools as part of the testing and as part of the decision for porting a new/existing device.

Information on commonly used benchmarks is available in the web, however i have good experience with the following ones:

– For Android – PassMark and Antutu (Which also provides Battery saver tool and CPU master to control the CPU speed)

http://www.androidbenchmark.net/passmark_chart.html

http://www.antutulabs.com/AnTuTu-Benchmark

 

– For iOS – PassMark and iBench

http://itunes.apple.com/us/app/ibench/id385703033?mt=8

Good Luck

Regards,

Eran Kinsbruner

Latest Mobile world news (July 2012)

Hi,

I’ve collected few topics which are “hot” these days in the mobile world and which i find interesting and relevant to the global audience.

  • Apple states that NFC support  (Near Field communication) might be included in the next iPhone 5 device

http://www.businessinsider.com/iphone-5-may-include-nfc-chip-for-mobile-payments-2012-6

  • RIM (research in motion) is considering selling its business to Facebook or Amazon (Treat this as a rumor rather than a fact)

http://www.businessinsider.com/rim-considers-selling-its-handset-business-2012-6

  • Time spent on mobile apps vs. web browsing is growing year by year – see below latest trends (Minutes per day):

  • Microsoft announces on the new Windows 8 OS with Internet Explorer 10 release with new features, enhancements and more, as well as new Metro customizable UI

http://windows.microsoft.com/en-US/windows-8/release-preview

  • Check out the list of 20 best mobile phones in the world according to techradar site:

http://www.techradar.com/news/phone-and-communications/mobile-phones/20-best-mobile-phones-in-the-world-today-645440?artc_pg=22

Enjoy 🙂

Regards,

Eran Kinsbruner