Wednesday, August 5, 2015

UI Testing in Xcode 7

X Code 7 introduces a new UI testing feature for fully integrated with X Code IDE. UI Testing, Recording and reporting are three major updates. The core technologies are XCTest and Accessibility feature. It requires new OS features iOS 9 and OS X 10.11 and Privacy protection for iOS devices enabled for development and connected to a trust host running on XCode. OS X must grant permissions to XCode helper for prompted on first run.



X Code is offering a target template that can target to be tested “Cocoa Touch UI Testing Bundle (iOS)” and “Cocoa UI Testing bundle (OS X)”. This target can create an UI project under project source code and place the UI test cases into same project.



UI Recording 
               Interact with your app and generate the code for new test cases and existing test cases. It will automatically find UI elements with synthesizing your user events. 



       APIs
There are 3 new classes in this release.

XCUIApplciation
  • Proxy for the tested Application and its run in a separate process
  • Launching target app If any existing process is running, It will terminates any pre existing instance
  • Its starting point for finding elements in the app 

Example : Testing the Add button
// Application 
let app =  XCUIApplciation()
app.launch()
// Element and Query 
let addButton = app.buttons["Add"]
addButton.tap()
// Assertion
XCTAssertEqual(app.tables.cells.count,1)

XCUIElement
  • Element Type: Button, Cell, Window, Etc. 
  • Identifiers: Accessibility identifier, Label, Class, Etc. 
  • Element hierarchy: Application is the root of tree elements. These elements can be used by queries with type of element and its identifiers.
  • Element uniqueness: Every XCUIElement is backed by a query and every query must resolve exactly one match like as XPath. If it matches multiple matches then it cause the test failure. This can be found by using exists property.
  • Event synthesis: It will simulate user interactions on elements. All APIs are platform-specific.  
For OS X:button.click();
For iOS : button.tap();  
For iOS and OS X textField.typeText("Hello World");
XCUIElementQuery
  • This API can help us for specifying elements and Queries work based on     relationships and filtering. Expressing relationships by Descendants, Children and containment.
  • Filtering can be done by

                                      Element Type: Button, Table, Menu, etc.
                                       Identifiers: Accessibility identifier, label, title, etc.
                                       Predicates: Value, Partial matching and others

                   Combining relationships and Filtering
descendantsMatchingType()
childrenMatchingType()
containingType()
    
                   allButtons = app.descendantsMatchingType(.Button)
                   childButtons = navBar.childrenMatchingType(.Button)
                          allCellsInTable = table.descendantsMatchingType(.Cell)
                   cellQuery = cells.containingType(.StaticText, identifier:”Groceries”) 

Test case results
            Show results for all tests
            Pass/fail
            Failure reason Performance metrics

ATBP - Android Testing Blue Print is now available !!!


Great collection of testing technique using the full spectrum of tools available to Android Testers. This repository will make it easy to get you started with test integration in existing and new projects. Android Testing Blue Print is available now on the android-testing-templates repository https://goo.gl/eSd8wC on Github. After cloning the repository please make sure you look at the “Getting Started Guide” first to get a glimpse of the project structure and how to run tests for each module.


https://github.com/googlesamples/android-testing-templates?linkId=16056862

Saturday, May 2, 2015

Espresso is faster than robotium

Espresso and Robotium are instrumentation-based frameworks, meaning they use Android Instrumentation to inspect and interact with Activities under test. The major advances in Espresso over Robotium:    

1.Synchronization: By default, instrumentation test logic runs on a different (instrumentation) thread than UI operations (processed on the UI thread). Without synchronization of test operations with UI updates, the tests will be prone to flakiness - i.e. will fail randomly because of timing issues. Espresso takes care of thread safety by seamlessly synchronizing test actions and assertions with the UI of the application under test. Robotium attempts to address this with sleep/retry mechanisms, which are not only unreliable, but also cause tests to run slower than necessary.

2.API: Espresso has a small, well-defined and predictable API, which is open to customization. 

3.Clear failure information: Espresso strives to provide rich debugging information when a failure happens. Further, you can customize the way failures are handled by Espresso with your own failure handler. 

For more information Read More

Monday, April 27, 2015

Android new testing library update

Android new testing library update

                      
          The new Android Testing Support Library provides an extensive framework for testing Android apps with espresso and Android Junit Runner with Android Studio. Now you can be able to run test cases from Android Studio with all connected devices. This library provides a set of APIs that allow you to quickly build and run test code for your apps, including JUnit 4 and functional user interface (UI) tests. You can run tests created using these APIs from the Android Studio IDE or from the command line. There are 3 major updates 1) Android Junit Runner. 2) Espresso. 3) Uiautomator 2.0


Android Junit Runner: 

         The Android Junit Runner class is a JUnit test runner that lets you run JUnit 3 or JUnit 4-style test classes on Android devices, including those using the Espresso and UI Automator testing frameworks. The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This class replaces the Instrumentation Test Runner class, which only supports JUnit 3 tests.

Uiautomator 2.0:

        The UI Automator testing framework provides a set of APIs to build UI tests that perform interactions on user apps and system apps. The UI Automator APIs allows you to perform operations such as opening the Settings menu or the app launcher in a test device. The UI Automator testing framework is well-suited for writing black box-style automated tests, where the test code does not rely on internal implementation details of the target app.

 Espresso:


                      
          The Espresso testing  framework provides a set of APIs to build UI tests to test user flows within an app. These APIs let you write automated UI tests that are concise and that run reliably. Espresso is well-suited for writing white box-style automated tests, where the test code utilizes implementation code details from the app under test. 


For more information Read More